-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
457 additions
and
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 { ColorField } from '.'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const meta = { | ||
component: ColorField, | ||
} satisfies Meta<typeof ColorField>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
}; |
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,16 @@ | ||
import { describe } from 'vitest'; | ||
import { render } from '@testing-library/react'; | ||
import { composeStories } from '@storybook/react'; | ||
|
||
import * as Stories from './ColorField.stories'; | ||
|
||
const { Default } = composeStories(Stories); | ||
|
||
describe('Component: ColorField', () => { | ||
describe('Snapshot', () => { | ||
it('Default', () => { | ||
const { asFragment } = render(<Default />); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
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,54 @@ | ||
import type { FC } from 'react'; | ||
import { useRef } from 'react'; | ||
|
||
import type { AriaColorFieldProps } from '@react-aria/color'; | ||
import { useColorField } from '@react-aria/color'; | ||
import { useColorFieldState } from '@react-stately/color'; | ||
|
||
import { cn } from '~/utils/tailwindUtil'; | ||
|
||
export type ColorFieldProps = { | ||
className?: string; | ||
} & AriaColorFieldProps; | ||
|
||
export const ColorField: FC<ColorFieldProps> = ({ className, label, ...props }) => { | ||
const state = useColorFieldState(props); | ||
const ref = useRef(null); | ||
const { | ||
labelProps, | ||
inputProps, | ||
descriptionProps, | ||
errorMessageProps, | ||
isInvalid, | ||
validationErrors, | ||
} = useColorField(props, state, ref); | ||
return ( | ||
<div className={cn('flex flex-row items-center justify-between', className)}> | ||
<label | ||
{...labelProps} | ||
className={cn('text-sm font-semibold text-gray-600', labelProps.className)} | ||
> | ||
{label} | ||
</label> | ||
<div | ||
className={ | ||
'rounded border-none bg-gray-100 py-1 px-2 text-sm font-semibold transition-colors hover:bg-gray-200 focus-visible:bg-gray-200 focus-visible:outline-0' | ||
} | ||
> | ||
<input {...inputProps} ref={ref} className={cn('', inputProps.className)} /> | ||
</div> | ||
{props.description && ( | ||
<div {...descriptionProps} className={cn('text-xs', descriptionProps.className)}> | ||
{props.description} | ||
</div> | ||
)} | ||
{isInvalid && ( | ||
<div {...errorMessageProps} className={cn('text-red text-xs', errorMessageProps.className)}> | ||
{validationErrors.join(' ')} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
ColorField.displayName = 'ColorField'; |
14 changes: 14 additions & 0 deletions
14
src/components/common/ColorField/ColorPicker/ColorPicker.stories.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 { ColorPicker } from '.'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const meta = { | ||
component: ColorPicker, | ||
} satisfies Meta<typeof ColorPicker>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
}; |
16 changes: 16 additions & 0 deletions
16
src/components/common/ColorField/ColorPicker/ColorPicker.test.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,16 @@ | ||
import { describe } from 'vitest'; | ||
import { render } from '@testing-library/react'; | ||
import { composeStories } from '@storybook/react'; | ||
|
||
import * as Stories from './ColorPicker.stories'; | ||
|
||
const { Default } = composeStories(Stories); | ||
|
||
describe('Component: ColorPicker', () => { | ||
describe('Snapshot', () => { | ||
it('Default', () => { | ||
const { asFragment } = render(<Default />); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
src/components/common/ColorField/ColorPicker/ColorPicker.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,16 @@ | ||
import type { ComponentProps, FC } from 'react'; | ||
|
||
import { cn } from '~/utils/tailwindUtil'; | ||
|
||
export type ColorPickerProps = {} & ComponentProps<'div'>; | ||
|
||
export const ColorPicker: FC<ColorPickerProps> = ({ className, children, ...props }) => { | ||
|
||
return ( | ||
<div {...props} className={cn('', className)}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
ColorPicker.displayName = 'ColorPicker'; |
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 @@ | ||
export * from './ColorPicker'; |
14 changes: 14 additions & 0 deletions
14
src/components/common/ColorField/ColorSwatch/ColorSwatch.stories.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 { ColorSwatch } from '.'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const meta = { | ||
component: ColorSwatch, | ||
} satisfies Meta<typeof ColorSwatch>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
}; |
16 changes: 16 additions & 0 deletions
16
src/components/common/ColorField/ColorSwatch/ColorSwatch.test.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,16 @@ | ||
import { describe } from 'vitest'; | ||
import { render } from '@testing-library/react'; | ||
import { composeStories } from '@storybook/react'; | ||
|
||
import * as Stories from './ColorSwatch.stories'; | ||
|
||
const { Default } = composeStories(Stories); | ||
|
||
describe('Component: ColorSwatch', () => { | ||
describe('Snapshot', () => { | ||
it('Default', () => { | ||
const { asFragment } = render(<Default />); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
src/components/common/ColorField/ColorSwatch/ColorSwatch.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,16 @@ | ||
import type { ComponentProps, FC } from 'react'; | ||
|
||
import { cn } from '~/utils/tailwindUtil'; | ||
|
||
export type ColorSwatchProps = {} & ComponentProps<'div'>; | ||
|
||
export const ColorSwatch: FC<ColorSwatchProps> = ({ className, children, ...props }) => { | ||
|
||
return ( | ||
<div {...props} className={cn('', className)}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
ColorSwatch.displayName = 'ColorSwatch'; |
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 @@ | ||
export * from './ColorSwatch'; |
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 @@ | ||
export * from './ColorField'; |
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 { NumberField } from '.'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const meta = { | ||
component: NumberField, | ||
} satisfies Meta<typeof NumberField>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
}; |
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,16 @@ | ||
import { describe } from 'vitest'; | ||
import { render } from '@testing-library/react'; | ||
import { composeStories } from '@storybook/react'; | ||
|
||
import * as Stories from './NumberField.stories'; | ||
|
||
const { Default } = composeStories(Stories); | ||
|
||
describe('Component: NumberField', () => { | ||
describe('Snapshot', () => { | ||
it('Default', () => { | ||
const { asFragment } = render(<Default />); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.