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
8a4daaf
commit 672bb5c
Showing
6 changed files
with
177 additions
and
62 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,40 @@ | ||
// | ||
// This source file is part of the Stanford Biodesign Digital Health Spezi Web Design System open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import { type Meta, type StoryObj } from '@storybook/react' | ||
import { fn } from '@storybook/test' | ||
import { useState } from 'react' | ||
import { SideLabel } from '@/components/SideLabel' | ||
import { Checkbox } from './Checkbox' | ||
|
||
const meta: Meta<typeof Checkbox> = { | ||
title: 'Components/Checkbox', | ||
component: Checkbox, | ||
args: { | ||
onCheckedChange: fn(), | ||
}, | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof Checkbox> | ||
|
||
export const Unchecked: Story = { args: { checked: false } } | ||
|
||
export const Chekced: Story = { args: { checked: true } } | ||
|
||
export const Functional = () => { | ||
const [checked, setChecked] = useState<boolean | 'indeterminate'>(false) | ||
return <Checkbox checked={checked} onCheckedChange={setChecked} /> | ||
} | ||
|
||
export const Labeled = () => ( | ||
<SideLabel label="Show unread only"> | ||
<Checkbox checked /> | ||
</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,31 @@ | ||
// | ||
// This source file is part of the Stanford Biodesign Digital Health Spezi Web Design System open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 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 element = screen.getByLabelText('Checkbox') | ||
fireEvent.click(element) | ||
|
||
const newCheckedValue = false | ||
expect(onCheckedChange).toHaveBeenCalledWith(newCheckedValue) | ||
}) | ||
}) |
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,34 @@ | ||
// | ||
// This source file is part of the Stanford Biodesign Digital Health Spezi Web Design System open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import * as CheckboxPrimitives from '@radix-ui/react-checkbox' | ||
import { | ||
type ComponentPropsWithoutRef, | ||
type ElementRef, | ||
forwardRef, | ||
} from 'react' | ||
import { cn } from '../../utils/className' | ||
import { CheckIcon } from 'lucide-react' | ||
|
||
export const Checkbox = forwardRef< | ||
ElementRef<typeof CheckboxPrimitives.Root>, | ||
ComponentPropsWithoutRef<typeof CheckboxPrimitives.Root> | ||
>(({ className, ...props }, ref) => ( | ||
<CheckboxPrimitives.Root | ||
className={cn( | ||
'hover:bg-violet3 flex size-[25px] appearance-none items-center justify-center rounded bg-white shadow-[0_0_0_2px_black] outline-none', | ||
className, | ||
)} | ||
{...props} | ||
ref={ref} | ||
> | ||
<CheckboxPrimitives.Indicator> | ||
<CheckIcon /> | ||
</CheckboxPrimitives.Indicator> | ||
</CheckboxPrimitives.Root> | ||
)) |
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: 2024 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