generated from StanfordBDHG/NextJSTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
0fed267
commit bff4f55
Showing
6 changed files
with
131 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// This source file is part of the Stanford Biodesign Digital Health Spezi Web Design System open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2025 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import { useArgs } from '@storybook/core/preview-api' | ||
import { type Meta, type StoryObj } from '@storybook/react' | ||
import { fn } from '@storybook/test' | ||
import { type ComponentProps } from 'react' | ||
import { SideLabel } from '@/components/SideLabel' | ||
import { Checkbox } from './Checkbox' | ||
|
||
const meta: Meta<typeof Checkbox> = { | ||
title: 'Components/Checkbox', | ||
component: Checkbox, | ||
args: { | ||
checked: false, | ||
onCheckedChange: fn(), | ||
}, | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof Checkbox> | ||
|
||
export const Default: Story = { | ||
render: function Render(args) { | ||
const [, updateArgs] = useArgs<ComponentProps<typeof Checkbox>>() | ||
return ( | ||
<Checkbox | ||
{...args} | ||
onCheckedChange={(checked) => updateArgs({ checked })} | ||
/> | ||
) | ||
}, | ||
} | ||
|
||
export const Checked: Story = { | ||
...Default, | ||
args: { | ||
checked: true, | ||
}, | ||
} | ||
|
||
export const Labeled = () => ( | ||
<SideLabel label="Show unread only"> | ||
<Checkbox /> | ||
</SideLabel> | ||
) |
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,30 @@ | ||
// | ||
// This source file is part of the Stanford Biodesign Digital Health Spezi Web Design System open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2025 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import { fireEvent, render, screen } from '@testing-library/react' | ||
import { vitest } from 'vitest' | ||
import { Checkbox } from '.' | ||
|
||
describe('Checkbox', () => { | ||
it('renders functional Checkbox element', () => { | ||
const onCheckedChange = vitest.fn() | ||
|
||
render( | ||
<Checkbox | ||
checked={true} | ||
onCheckedChange={onCheckedChange} | ||
aria-label="Checkbox" | ||
/>, | ||
) | ||
|
||
const checkbox = screen.getByLabelText('Checkbox') | ||
fireEvent.click(checkbox) | ||
|
||
expect(onCheckedChange).toHaveBeenCalledWith(false) | ||
}) | ||
}) |
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,35 @@ | ||
// | ||
// This source file is part of the Stanford Biodesign Digital Health Spezi Web Design System open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2025 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import * as CheckboxPrimitive from '@radix-ui/react-checkbox' | ||
import { | ||
type ComponentPropsWithoutRef, | ||
type ElementRef, | ||
forwardRef, | ||
} from 'react' | ||
import { cn } from '@/utils/className' | ||
|
||
type CheckboxProps = ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> | ||
|
||
export const Checkbox = forwardRef< | ||
ElementRef<typeof CheckboxPrimitive.Root>, | ||
CheckboxProps | ||
>(({ className, ...props }, ref) => ( | ||
<CheckboxPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
'focus-ring flex-center peer size-4 shrink-0 rounded border border-input disabled:cursor-not-allowed disabled:opacity-50', | ||
className, | ||
)} | ||
{...props} | ||
> | ||
<CheckboxPrimitive.Indicator className="flex-center size-2.5 rounded-sm bg-primary" /> | ||
</CheckboxPrimitive.Root> | ||
)) | ||
|
||
Checkbox.displayName = CheckboxPrimitive.Root.displayName |
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 @@ | ||
// | ||
// This source file is part of the Stanford Biodesign Digital Health Spezi Web Design System open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2025 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
export * from './Checkbox' |
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