-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(solid): add color picker (#810)
- Loading branch information
1 parent
8339a4c
commit ecccae4
Showing
27 changed files
with
516 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
output { | ||
font-size: 14px; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='content'] { | ||
max-width: 260px; | ||
display: flex; | ||
|
This file contains 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 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
7 changes: 7 additions & 0 deletions
7
packages/solid/src/color-picker/color-picker-area-context.tsx
This file contains 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,7 @@ | ||
import type { AreaProps } from '@zag-js/color-picker/dist/color-picker.types' | ||
import { createContext } from '../create-context' | ||
|
||
export const [ColorPickerAreaProvider, useColorPickerAreaContext] = createContext<AreaProps>({ | ||
hookName: 'useColorPickerAreaContext', | ||
providerName: '<ColorPickerAreaProvider />', | ||
}) |
15 changes: 15 additions & 0 deletions
15
packages/solid/src/color-picker/color-picker-area-gradient.tsx
This file contains 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,15 @@ | ||
import { mergeProps } from 'solid-js' | ||
import { ark, type HTMLArkProps } from '../factory' | ||
import { useColorPickerAreaContext } from './color-picker-area-context' | ||
import { useColorPickerContext } from './color-picker-context' | ||
|
||
export type ColorPickerAreaGradientProps = HTMLArkProps<'div'> | ||
|
||
export const ColorPickerAreaGradient = (props: ColorPickerAreaGradientProps) => { | ||
const colorPicker = useColorPickerContext() | ||
const area = useColorPickerAreaContext() | ||
|
||
const mergedProps = mergeProps(colorPicker().getAreaGradientProps(area), props) | ||
|
||
return <ark.div {...mergedProps} /> | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/solid/src/color-picker/color-picker-area-thumb.tsx
This file contains 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,15 @@ | ||
import { mergeProps } from 'solid-js' | ||
import { ark, type HTMLArkProps } from '../factory' | ||
import { useColorPickerAreaContext } from './color-picker-area-context' | ||
import { useColorPickerContext } from './color-picker-context' | ||
|
||
export type ColorPickerAreaThumbProps = HTMLArkProps<'div'> | ||
|
||
export const ColorPickerAreaThumb = (props: ColorPickerAreaThumbProps) => { | ||
const colorPicker = useColorPickerContext() | ||
const area = useColorPickerAreaContext() | ||
|
||
const mergedProps = mergeProps(colorPicker().getAreaThumbProps(area), props) | ||
|
||
return <ark.div {...mergedProps} /> | ||
} |
This file contains 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,21 @@ | ||
import type { AreaProps } from '@zag-js/color-picker/dist/color-picker.types' | ||
import { mergeProps } from 'solid-js' | ||
import { createSplitProps } from '../create-split-props' | ||
import { ark, type HTMLArkProps } from '../factory' | ||
import { ColorPickerAreaProvider } from './color-picker-area-context' | ||
import { useColorPickerContext } from './color-picker-context' | ||
|
||
export type ColorPickerAreaProps = HTMLArkProps<'div'> & AreaProps | ||
|
||
export const ColorPickerArea = (props: ColorPickerAreaProps) => { | ||
const [areaProps, divprops] = createSplitProps<AreaProps>()(props, ['xChannel', 'yChannel']) | ||
const colorPicker = useColorPickerContext() | ||
const mergedProps = mergeProps(colorPicker().getAreaProps(areaProps), divprops) | ||
|
||
console.log({ areaProps }) | ||
return ( | ||
<ColorPickerAreaProvider value={areaProps}> | ||
<ark.div {...mergedProps} /> | ||
</ColorPickerAreaProvider> | ||
) | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/solid/src/color-picker/color-picker-channel-input.tsx
This file contains 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,19 @@ | ||
import type { Assign } from '@polymorphic-factory/solid' | ||
import type { ChannelInputProps } from '@zag-js/color-picker/dist/color-picker.types' | ||
import { mergeProps } from 'solid-js' | ||
import { createSplitProps } from '../create-split-props' | ||
import { ark, type HTMLArkProps } from '../factory' | ||
import { useColorPickerContext } from './color-picker-context' | ||
|
||
export type ColorPickerChannelInputProps = Assign<HTMLArkProps<'input'>, ChannelInputProps> | ||
|
||
export const ColorPickerChannelInput = (props: ColorPickerChannelInputProps) => { | ||
const [channelProps, inputProps] = createSplitProps<ChannelInputProps>()(props, [ | ||
'channel', | ||
'orientation', | ||
]) | ||
const colorPicker = useColorPickerContext() | ||
const mergedProps = mergeProps(colorPicker().getChannelInputProps(channelProps), inputProps) | ||
|
||
return <ark.input {...mergedProps} /> | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/solid/src/color-picker/color-picker-channel-slider-context.tsx
This file contains 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,9 @@ | ||
import type { ChannelProps } from '@zag-js/color-picker/dist/color-picker.types' | ||
import { createContext } from '../create-context' | ||
|
||
export const [ColorPickerSliderProvider, useColorPickerSliderContext] = createContext<ChannelProps>( | ||
{ | ||
hookName: 'useColorPickerSliderContext', | ||
providerName: '<ColorPickerSliderProvider />', | ||
}, | ||
) |
14 changes: 14 additions & 0 deletions
14
packages/solid/src/color-picker/color-picker-channel-slider-thumb.tsx
This file contains 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,14 @@ | ||
import { mergeProps } from 'solid-js' | ||
import { ark, type HTMLArkProps } from '../factory' | ||
import { useColorPickerSliderContext } from './color-picker-channel-slider-context' | ||
import { useColorPickerContext } from './color-picker-context' | ||
|
||
export type ColorPickerSliderThumbProps = HTMLArkProps<'div'> | ||
|
||
export const ColorPickerSliderThumb = (props: ColorPickerSliderThumbProps) => { | ||
const colorPicker = useColorPickerContext() | ||
const slider = useColorPickerSliderContext() | ||
const mergedProps = mergeProps(colorPicker().getChannelSliderThumbProps(slider), props) | ||
|
||
return <ark.div {...mergedProps} /> | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/solid/src/color-picker/color-picker-channel-slider-track.tsx
This file contains 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,26 @@ | ||
import type { ChannelProps } from '@zag-js/color-picker/dist/color-picker.types' | ||
import { mergeProps } from 'solid-js' | ||
import { createSplitProps } from '../create-split-props' | ||
import { ark, type HTMLArkProps } from '../factory' | ||
import { ColorPickerSliderProvider } from './color-picker-channel-slider-context' | ||
import { useColorPickerContext } from './color-picker-context' | ||
|
||
export type ColorPickerSliderTrackProps = HTMLArkProps<'div'> & ChannelProps | ||
|
||
export const ColorPickerSliderTrack = (props: ColorPickerSliderTrackProps) => { | ||
const [channelProps, divProps] = createSplitProps<ChannelProps>()(props, [ | ||
'channel', | ||
'orientation', | ||
]) | ||
const colorPicker = useColorPickerContext() | ||
const mergedProps = mergeProps(colorPicker().getChannelSliderTrackProps(channelProps), divProps) | ||
|
||
return ( | ||
<ColorPickerSliderProvider value={channelProps}> | ||
<ark.div {...mergedProps} /> | ||
{/* <ark.div {...colorPicker().getChannelSliderBackgroundProps(channelProps)}> */} | ||
{/* {children} | ||
</ark.div> */} | ||
</ColorPickerSliderProvider> | ||
) | ||
} |
This file contains 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,10 @@ | ||
import { ark, type HTMLArkProps } from '../factory' | ||
import { useColorPickerContext } from './color-picker-context' | ||
|
||
export type ColorPickerContentProps = HTMLArkProps<'div'> | ||
|
||
export const ColorPickerContent = (props: ColorPickerContentProps) => { | ||
const colorPicker = useColorPickerContext() | ||
|
||
return <ark.div {...colorPicker().contentProps} {...props} /> | ||
} |
This file contains 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,9 @@ | ||
import { createContext } from '../create-context' | ||
import { type UseColorPickerReturn } from './use-color-picker' | ||
|
||
export type ColorPickerContext = UseColorPickerReturn | ||
|
||
export const [ColorPickerProvider, useColorPickerContext] = createContext<ColorPickerContext>({ | ||
hookName: 'useColorPickerContext', | ||
providerName: '<ColorPickerProvider />', | ||
}) |
10 changes: 10 additions & 0 deletions
10
packages/solid/src/color-picker/color-picker-eye-dropper-trigger.tsx
This file contains 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,10 @@ | ||
import { ark, type HTMLArkProps } from '../factory' | ||
import { useColorPickerContext } from './color-picker-context' | ||
|
||
export type ColorPickerEyeDropperTriggerProps = HTMLArkProps<'div'> | ||
|
||
export const ColorPickerEyeDropperTrigger = (props: ColorPickerEyeDropperTriggerProps) => { | ||
const dialog = useColorPickerContext() | ||
|
||
return <ark.div {...dialog().eyeDropperTriggerProps} {...props} /> | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/solid/src/color-picker/color-picker-swatch-group.tsx
This file contains 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,8 @@ | ||
import { ark, type HTMLArkProps } from '../factory' | ||
import { parts } from './color-picker.anatomy' | ||
|
||
export type ColorPickerSwatchGroupProps = HTMLArkProps<'div'> | ||
|
||
export const ColorPickerSwatchGroup = (props: ColorPickerSwatchGroupProps) => ( | ||
<ark.div {...parts.swatchGroup.attrs} {...props} /> | ||
) |
This file contains 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,20 @@ | ||
import type { Assign } from '@polymorphic-factory/solid' | ||
import type { SwatchProps } from '@zag-js/color-picker/dist/color-picker.types' | ||
import { mergeProps } from 'solid-js' | ||
import { createSplitProps } from '../create-split-props' | ||
import { ark, type HTMLArkProps } from '../factory' | ||
import { useColorPickerContext } from './color-picker-context' | ||
|
||
export type ColorPickerSwatchProps = Assign<HTMLArkProps<'button'>, SwatchProps> | ||
|
||
export const ColorPickerSwatch = (props: ColorPickerSwatchProps) => { | ||
const [swatchProps, buttonProps] = createSplitProps<SwatchProps>()(props, ['readOnly', 'value']) | ||
const colorPicker = useColorPickerContext() | ||
const mergedProps = mergeProps(colorPicker().getSwatchProps(swatchProps), buttonProps) | ||
|
||
return ( | ||
<ark.button {...mergedProps} disabled={swatchProps.readOnly}> | ||
<ark.div {...colorPicker().getSwatchBackgroundProps(swatchProps)} /> | ||
</ark.button> | ||
) | ||
} |
This file contains 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,21 @@ | ||
import { createAnatomy } from '@zag-js/anatomy' | ||
// TODO replace with anatomy from @zag-js/color-picker | ||
// import { anatomy } from '@zag-js/color-picker' | ||
|
||
const anatomy = createAnatomy('color-picker', [ | ||
'area', | ||
'areaThumb', | ||
'areaGradient', | ||
'channelSliderTrack', | ||
'channelSliderTrackBg', | ||
'channelSliderThumb', | ||
'channelInput', | ||
'swatch', | ||
'swatchBg', | ||
'content', | ||
'label', | ||
'eyeDropTrigger', | ||
]) | ||
|
||
export const colorPickerAnatomy = anatomy.extendWith('swatchGroup') | ||
export const parts = colorPickerAnatomy.build() |
This file contains 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,76 @@ | ||
output { | ||
font-size: 14px; | ||
display: flex; | ||
gap: 8px; | ||
align-items: center; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='content'] { | ||
max-width: 260px; | ||
display: flex; | ||
flex-direction: column; | ||
box-sizing: border-box; | ||
gap: 16px; | ||
padding: 24px; | ||
border: 1px solid #d5d5d5; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='area'] { | ||
height: 200px; | ||
border-radius: 4px; | ||
border: 1px solid #ebebeb; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='area-gradient'] { | ||
background: rgb(142, 142, 142); | ||
border-radius: 4px; | ||
height: 200px; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='area-thumb'], | ||
[data-scope='color-picker'][data-part='channel-slider-thumb'] { | ||
border: 2px solid white; | ||
border-radius: 9999px; | ||
box-sizing: border-box; | ||
transform: translate(-50%, -50%); | ||
box-shadow: black 0px 0px 0px 1px, black 0px 0px 0px 1px inset; | ||
width: 16px; | ||
height: 16px; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='channel-slider-track'] { | ||
height: 20px; | ||
border-radius: 4px; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='channel-slider-track-bg'] { | ||
border-radius: 4px; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='channel-input'] { | ||
border-radius: 4px; | ||
width: 100%; | ||
border: 1px solid #c2c2c2; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='channel-input']::-webkit-outer-spin-button, | ||
[data-scope='color-picker'][data-part='channel-input']::-webkit-inner-spin-button { | ||
-webkit-appearance: none; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='swatch-group'] { | ||
display: flex; | ||
gap: 4px; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='swatch'] { | ||
all: unset; | ||
border-radius: 4px; | ||
width: 20px; | ||
height: 20px; | ||
flex-shrink: 0; | ||
} | ||
|
||
[data-scope='color-picker'][data-part='swatch-bg'] { | ||
border-radius: 4px; | ||
} |
This file contains 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,56 @@ | ||
import { | ||
ColorPicker, | ||
ColorPickerArea, | ||
ColorPickerAreaGradient, | ||
ColorPickerAreaThumb, | ||
ColorPickerChannelInput, | ||
ColorPickerContent, | ||
ColorPickerEyeDropperTrigger, | ||
ColorPickerSliderThumb, | ||
ColorPickerSliderTrack, | ||
ColorPickerSwatch, | ||
ColorPickerSwatchGroup, | ||
} from './' | ||
import './color-picker.css' | ||
|
||
export const Basic = () => ( | ||
<ColorPicker value="hsla(10, 81%, 59%, 1)"> | ||
{(api) => { | ||
const [hue, saturation, lightness] = api.channels | ||
return ( | ||
<ColorPickerContent> | ||
<output> | ||
<ColorPickerSwatch value={api.value} readOnly /> | ||
<span>{api.value}</span> | ||
</output> | ||
|
||
<ColorPickerArea xChannel={saturation} yChannel={lightness}> | ||
<ColorPickerAreaGradient /> | ||
<ColorPickerAreaThumb /> | ||
</ColorPickerArea> | ||
|
||
<ColorPickerSliderTrack channel={hue}> | ||
<ColorPickerSliderThumb /> | ||
</ColorPickerSliderTrack> | ||
<ColorPickerSliderTrack channel="alpha"> | ||
<ColorPickerSliderThumb /> | ||
</ColorPickerSliderTrack> | ||
|
||
<ColorPickerChannelInput channel={hue} /> | ||
<ColorPickerChannelInput channel={saturation} /> | ||
<ColorPickerChannelInput channel={lightness} /> | ||
<ColorPickerChannelInput channel="alpha" /> | ||
<ColorPickerChannelInput channel="hex" /> | ||
|
||
<ColorPickerSwatchGroup> | ||
<ColorPickerSwatch value="hsla(153, 46%, 13%, 1)" /> | ||
<ColorPickerSwatch value="hsla(356, 100%, 54%, 1)" /> | ||
</ColorPickerSwatchGroup> | ||
<ColorPickerEyeDropperTrigger> | ||
<button>Pick color</button> | ||
</ColorPickerEyeDropperTrigger> | ||
</ColorPickerContent> | ||
) | ||
}} | ||
</ColorPicker> | ||
) |
Oops, something went wrong.
ecccae4
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.
Successfully deployed to the following URLs:
ark-website – ./
ark-website-three.vercel.app
ark-website-chakra-ui.vercel.app
ark-ui.com
ark-website-git-main-chakra-ui.vercel.app