Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: color picker #1086

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ethanalvizo
Copy link
Contributor

@ethanalvizo ethanalvizo commented Jan 17, 2025

Only default implementation of color picker included in this ticket. The custom color editor options will be implemented in a separate ticket

@ethanalvizo ethanalvizo self-assigned this Jan 17, 2025
@ethanalvizo ethanalvizo marked this pull request as ready for review January 27, 2025 04:54
@ethanalvizo ethanalvizo requested a review from mofojed January 27, 2025 04:54
) -> Element:
"""
A ColorPicker combines a swatch with a customizable popover for editing a color.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs pydocs for the args

rounding: str = "default",
value: str | None = None,
default_value: str | None = None,
on_change: Callable[[str], None] | None = None, # should be Color type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think should just use the CSSColor type... or define a HexColor type...
The Color type returned by default is an object that can convert between many types, but I think we should be fine just to convert to hex string and use that... unless we want to wrap our own Color object type but that might be a bit complicated... @dsmmcken what format should this fire off?


return [
ui.color_picker(label="Uncontrolled", default_value="#65C4D7"),
ui.color_picker(label="Controlled", value=value, on_change=set_value),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example isn't working currently, breaks when you pick a new color.

TypeError

color.getChannelValue is not a function

TypeError: color.getChannelValue is not a function
    at $2993fcad7650b98d$export$9060ae606178d849 (http://localhost:4000/ide/node_modules/.vite/deps/chunk-5VQURW7F.js?v=23333ff8:19358:37)
    at $d68786ae409fa722$var$ColorSwatch (http://localhost:4000/ide/node_modules/.vite/deps/@adobe_react-spectrum.js?v=23333ff8:8761:83)
    at renderWithHooks (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:11478:26)
    at updateForwardRef (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:13112:28)
    at beginWork (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:14515:22)
    at HTMLUnknownElement.callCallback2 (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:3901:22)
    at Object.invokeGuardedCallbackDev (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:3926:24)
    at invokeGuardedCallback (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:3960:39)
    at beginWork$1 (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:17637:15)
    at performUnitOfWork (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:16861:20)
    at workLoopSync (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:16815:13)
    at renderRootSync (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:16790:15)
    at performSyncWorkOnRoot (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:16530:26)
    at http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:8900:34
    at unstable_runWithPriority (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:353:20)
    at runWithPriority$1 (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:8860:18)
    at flushSyncCallbackQueueImpl (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:8896:17)
    at flushSyncCallbackQueue (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:8886:11)
    at Object.batchedUpdates$1 [as unstable_batchedUpdates] (http://localhost:4000/ide/node_modules/.vite/deps/chunk-DZEH73WR.js?v=23333ff8:16589:15)
    at eval (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:74114:20)
    at eval (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9411:24)
    at callMethod (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9515:18)
    at noopMiddleware (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9547:10)
    at JSONRPCServer2.callMethod (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9527:51)
    at JSONRPCServer2.eval (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9476:31)
    at step (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9354:17)
    at Object.eval [as next] (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9306:14)
    at eval (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9293:67)
    at new Promise (<anonymous>)
    at __awaiter$1 (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9275:10)
    at JSONRPCServer2.receiveSingle (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9467:14)
    at JSONRPCServer2.receive (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9440:21)
    at JSONRPCServerAndClient2.eval (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9734:38)
    at step (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9662:17)
    at Object.eval [as next] (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9614:14)
    at eval (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9601:67)
    at new Promise (<anonymous>)
    at __awaiter (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9583:10)
    at JSONRPCServerAndClient2.receiveAndSend (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:9724:14)
    at receiveData (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:74203:32)
    at eval (eval at <anonymous> (http://localhost:4000/ide/node_modules/.vite/deps/chunk-U5HSWCVV.js?v=23333ff8:172:22), <anonymous>:74215:11)
    at Object.$lambda$3 (http://localhost:4000/jsapi/dh-core.js:12277:5)
    at Function.onInvoke_126 (http://localhost:4000/jsapi/dh-core.js:24631:17)
    at lambda (http://localhost:4000/jsapi/dh-core.js:195:22)
    at Array.forEach (<anonymous>)
    at Object.$fireEvent (http://localhost:4000/jsapi/dh-core.js:12256:15)
    at Object.$lambda$6_3 (http://localhost:4000/jsapi/dh-core.js:31795:12)
    at Function.apply_176 (http://localhost:4000/jsapi/dh-core.js:32022:10)
    at lambda (http://localhost:4000/jsapi/dh-core.js:195:22)
    at http://localhost:4000/jsapi/dh-internal.js:1:746013
    at Array.forEach (<anonymous>)
    at http://localhost:4000/jsapi/dh-internal.js:1:745992
    at http://localhost:4000/jsapi/dh-internal.js:1:11539
    at Array.forEach (<anonymous>)
    at e.rawOnMessage (http://localhost:4000/jsapi/dh-internal.js:1:11501)
    at http://localhost:4000/jsapi/dh-internal.js:1:9314
    at Array.forEach (<anonymous>)
    at e.onTransportChunk (http://localhost:4000/jsapi/dh-internal.js:1:9189)
    at Object.lambda$1_12 (http://localhost:4000/jsapi/dh-core.js:25154:21)
    at Function.onChunk (http://localhost:4000/jsapi/dh-core.js:25196:10)
    at lambda (http://localhost:4000/jsapi/dh-core.js:195:22)
    at Object.$onMessage (http://localhost:4000/jsapi/dh-core.js:25234:35)
    at MultiplexedWebsocketTransport$3methodref$onMessage$Type.handleEvent_2 [as handleEvent] (http://localhost:4000/jsapi/dh-core.js:25376:10)


return (
// eslint-disable-next-line react/jsx-props-no-spreading
<DHCColorPicker {...otherProps}>{children}</DHCColorPicker>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should debounce the onChange listener, may also need to convert type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants