-
Notifications
You must be signed in to change notification settings - Fork 13
feat(color-picker): migrate to culori and add add OKLCH support #816
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
Open
paanSinghCoder
wants to merge
7
commits into
main
Choose a base branch
from
feat/color-picker-culori-oklch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
af695d2
feat(color-picker): migrate to culori and add OKLCH mode
paanSinghCoder 5a23cd6
chore(color-picker): narrow ModeType via `as const`
paanSinghCoder 59c2491
feat(color-picker): enhance OKLCH mode functionality and documentation
paanSinghCoder 6322ee5
feat(color-picker): improve color picker functionality and performance
paanSinghCoder ed8bbca
feat(color-picker): add copyable functionality to ColorPicker.Input
paanSinghCoder 735a556
fix(color-picker): handle pointercancel event in color picker areas
paanSinghCoder 51bbf6b
refactor(color-picker): correct HslView type definition
paanSinghCoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| 'use client'; | ||
|
|
||
| import { Button, ColorPicker, Flex, Popover, Text } from '@raystack/apsara'; | ||
| import { useState } from 'react'; | ||
|
|
||
| const cardStyle = { | ||
| width: 280, | ||
| padding: 16, | ||
| borderRadius: 8, | ||
| background: 'var(--rs-color-background-base-primary)', | ||
| border: '1px solid var(--rs-color-border-base-primary)' | ||
| } as const; | ||
|
|
||
| export default function ColorPickerExamplesPage() { | ||
| const [controlledValue, setControlledValue] = useState( | ||
| 'oklch(0.5438 0.191 267.01)' | ||
| ); | ||
| const [controlledMode, setControlledMode] = useState< | ||
| 'hex' | 'rgb' | 'hsl' | 'oklch' | ||
| >('oklch'); | ||
| const [popoverColor, setPopoverColor] = useState('#DA2929'); | ||
|
|
||
| return ( | ||
| <Flex | ||
| direction='column' | ||
| gap={9} | ||
| style={{ | ||
| padding: 32, | ||
| background: 'var(--rs-color-background-neutral-secondary)', | ||
| minHeight: '100vh' | ||
| }} | ||
| > | ||
| <Flex direction='column' gap={2}> | ||
| <Text size='large' weight='medium'> | ||
| ColorPicker | ||
| </Text> | ||
| <Text size='small' variant='secondary'> | ||
| The picker edits internally in OKLCH for perceptual uniformity. The | ||
| area pad shows a chroma × lightness cross-section at the selected hue; | ||
| the <code>mode</code> prop selects the output format (hex / rgb / hsl | ||
| / oklch). | ||
| </Text> | ||
| </Flex> | ||
|
|
||
| <Flex gap={6} wrap='wrap'> | ||
| <Flex direction='column' gap={3} style={cardStyle}> | ||
| <Text size='small' weight='medium'> | ||
| Default (hex) | ||
| </Text> | ||
| <ColorPicker defaultValue='#DA2929'> | ||
| <ColorPicker.Area /> | ||
| <ColorPicker.Hue /> | ||
| <ColorPicker.Alpha /> | ||
| <Flex direction='row' gap={2}> | ||
| <ColorPicker.Mode /> | ||
| <ColorPicker.Input copyable /> | ||
| </Flex> | ||
| </ColorPicker> | ||
| </Flex> | ||
|
|
||
| <Flex direction='column' gap={3} style={cardStyle}> | ||
| <Text size='small' weight='medium'> | ||
| OKLCH mode | ||
| </Text> | ||
| <Text size='micro' variant='secondary'> | ||
| <code>defaultValue='oklch(0.5438 0.191 267.01)'</code>{' '} | ||
| with <code>defaultMode='oklch'</code>. | ||
| </Text> | ||
| <ColorPicker | ||
| defaultValue='oklch(0.5438 0.191 267.01)' | ||
| defaultMode='oklch' | ||
| > | ||
| <ColorPicker.Area /> | ||
| <ColorPicker.Hue /> | ||
| <ColorPicker.Alpha /> | ||
| <Flex direction='row' gap={2}> | ||
| <ColorPicker.Mode /> | ||
| <ColorPicker.Input copyable /> | ||
| </Flex> | ||
| </ColorPicker> | ||
| </Flex> | ||
|
|
||
| <Flex direction='column' gap={3} style={cardStyle}> | ||
| <Text size='small' weight='medium'> | ||
| Controlled — emits live value | ||
| </Text> | ||
| <ColorPicker | ||
| value={controlledValue} | ||
| mode={controlledMode} | ||
| onValueChange={(value, mode) => { | ||
| setControlledValue(value); | ||
| setControlledMode(mode as typeof controlledMode); | ||
| }} | ||
| onModeChange={mode => | ||
| setControlledMode(mode as typeof controlledMode) | ||
| } | ||
| > | ||
| <ColorPicker.Area /> | ||
| <ColorPicker.Hue /> | ||
| <ColorPicker.Alpha /> | ||
| <Flex direction='row' gap={2}> | ||
| <ColorPicker.Mode /> | ||
| <ColorPicker.Input copyable /> | ||
| </Flex> | ||
| </ColorPicker> | ||
| <Flex direction='column' gap={1}> | ||
| <Text size='micro' variant='secondary'> | ||
| value: | ||
| </Text> | ||
| <Text | ||
| size='small' | ||
| style={{ | ||
| fontFamily: 'monospace', | ||
| wordBreak: 'break-all' | ||
| }} | ||
| > | ||
| {controlledValue} | ||
| </Text> | ||
| <Text size='micro' variant='secondary' style={{ marginTop: 4 }}> | ||
| mode: <code>{controlledMode}</code> | ||
| </Text> | ||
| </Flex> | ||
| </Flex> | ||
|
|
||
| <Flex direction='column' gap={3} style={cardStyle}> | ||
| <Text size='small' weight='medium'> | ||
| Popover trigger | ||
| </Text> | ||
| <Popover> | ||
| <Popover.Trigger | ||
| render={ | ||
| <Button | ||
| style={{ | ||
| width: 60, | ||
| height: 60, | ||
| background: popoverColor | ||
| }} | ||
| /> | ||
| } | ||
| /> | ||
| <Popover.Content> | ||
| <ColorPicker | ||
| value={popoverColor} | ||
| onValueChange={setPopoverColor} | ||
| style={{ width: 240, height: 320 }} | ||
| > | ||
| <ColorPicker.Area /> | ||
| <ColorPicker.Hue /> | ||
| <ColorPicker.Alpha /> | ||
| <Flex direction='row' gap={2}> | ||
| <ColorPicker.Mode /> | ||
| <ColorPicker.Input copyable /> | ||
| </Flex> | ||
| </ColorPicker> | ||
| </Popover.Content> | ||
| </Popover> | ||
| <Text | ||
| size='small' | ||
| style={{ | ||
| fontFamily: 'monospace', | ||
| wordBreak: 'break-all' | ||
| }} | ||
| > | ||
| {popoverColor} | ||
| </Text> | ||
| </Flex> | ||
| </Flex> | ||
| </Flex> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving only the slider values leaves the first component of the OKLCH value unchanged, making it look like the value isn't updating. Since the cursor also resets upon updating the slider, consider increasing the card's width to resolve this.