Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed Feb 18, 2025
1 parent 83111d3 commit d15c2cb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 56 deletions.
2 changes: 1 addition & 1 deletion apps/docs/src/routes/docs/core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const CORE_NAV_SECTIONS: NavSection[] = [
{
title: "Color Channel Field",
href: "/docs/core/components/color-channel-field",
status: "unreleased",
status: "new",
},
{
title: "Color Field",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ The color channel field supports optional increment/decrement triggers that are

| Prop | Description |
| :-------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| value | `Color` <br/> The controlled formatted value of the field. |
| value | `Color` <br/> The controlled value of the field. |
| defaultValue | `Color` <br/> The default value when initially rendered. Useful when you do not need to control the value. |
| colorSpace | `ColorSpace` <br/> The color space that the field operates in. The `channel` must be in this color space. |
| onChange | `(value: Color) => void` <br/> Event handler called when the value of the field changes. |
Expand Down
9 changes: 0 additions & 9 deletions packages/core/dev/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { ColorWheel } from "../src/color-wheel";

export default function App() {
return (
<>
<ColorWheel class="ColorWheelRoot" thickness={30}>
<ColorWheel.Track class="ColorWheelTrack">
<ColorWheel.Thumb class="ColorWheelThumb">
<ColorWheel.Input />
</ColorWheel.Thumb>
</ColorWheel.Track>
</ColorWheel>
</>
);
}
37 changes: 0 additions & 37 deletions packages/core/dev/index.css
Original file line number Diff line number Diff line change
@@ -1,37 +0,0 @@
.ColorWheelRoot {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
user-select: none;
touch-action: none;
}

.ColorWheelTrack {
position: relative;
height: 160px;
width: 160px;
}

.ColorWheelThumb {
display: block;
width: 16px;
height: 16px;
border-radius: 9999px;
border: 2px solid #fff;
box-shadow: 0 0 0 1px #0000006b;
}

.ColorWheelThumb:focus {
outline: none;
}

.ColorWheelLabel {
display: flex;
justify-content: space-between;
width: 100%;
}

html {
background: hsl(240 4% 16%);
}
19 changes: 11 additions & 8 deletions packages/core/src/color-channel-field/color-channel-field-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export function ColorChannelFieldRoot<T extends ValidComponent = "div">(
const defaultId = `colorchannelfield-${createUniqueId()}`;

const mergedProps = mergeDefaultProps(
{ id: defaultId },
{
id: defaultId,
},
props as ColorChannelFieldRootProps,
);

Expand All @@ -72,10 +74,6 @@ export function ColorChannelFieldRoot<T extends ValidComponent = "div">(
"colorSpace",
]);

if (!local.value && !local.defaultValue) {
throw new Error("ColorChannelField requires a value or defaultValue");
}

const [value, setValue] = createControllableSignal<Color>({
value: () => local.value,
defaultValue: () => local.defaultValue,
Expand All @@ -100,7 +98,12 @@ export function ColorChannelFieldRoot<T extends ValidComponent = "div">(
setValue(
color()!.withChannelValue(
local.channel,
!Number.isNaN(value) ? value * multiplier() : Number.NaN,
!Number.isNaN(value)
? Math.max(
Math.min(value * multiplier(), range().maxValue),
range().minValue,
)
: Number.NaN,
),
);
};
Expand All @@ -114,9 +117,9 @@ export function ColorChannelFieldRoot<T extends ValidComponent = "div">(
>
>
>
value={
rawValue={
Number.isNaN(color()!.getChannelValue(local.channel))
? ""
? undefined
: color()!.getChannelValue(local.channel) / multiplier()
}
minValue={range().minValue / multiplier()}
Expand Down

0 comments on commit d15c2cb

Please sign in to comment.