-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from 8845musign/imple-divider
Imple Divider Component
- Loading branch information
Showing
9 changed files
with
265 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.divider { | ||
width: var(--width); | ||
min-width: var(--min-width); | ||
max-width: var(--max-width); | ||
height: 1px; | ||
margin: var(--margin-top) var(--margin-right) var(--margin-bottom) var(--margin-left); | ||
border: none; | ||
} | ||
|
||
.divider.gray { | ||
background-color: var(--color-border); | ||
} | ||
|
||
.divider.primary { | ||
background-color: var(--color-primary); | ||
} |
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,42 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { Divider } from './Divider'; | ||
|
||
describe('<Divider>', () => { | ||
it('receives date attribute', async () => { | ||
render(<Divider data-testid="divider" />); | ||
const divider = screen.getByTestId('divider'); | ||
|
||
expect(divider).toBeInTheDocument(); | ||
}); | ||
|
||
it('receives max-width', async () => { | ||
render(<Divider data-testid="divider" maxWidth="400px" />); | ||
const divider = screen.getByTestId('divider'); | ||
|
||
expect(divider).toHaveStyle('--max-width: 400px'); | ||
}); | ||
|
||
it('receives min-width', async () => { | ||
render(<Divider data-testid="divider" minWidth="400px" />); | ||
const divider = screen.getByTestId('divider'); | ||
|
||
expect(divider).toHaveStyle('--min-width: 400px'); | ||
}); | ||
|
||
it('receives width', async () => { | ||
render(<Divider data-testid="divider" width="400px" />); | ||
const divider = screen.getByTestId('divider'); | ||
|
||
expect(divider).toHaveStyle('--width: 400px'); | ||
}); | ||
|
||
it('receives margins', async () => { | ||
render(<Divider data-testid="divider" mt="xxs" mr="xs" mb="sm" ml="md" />); | ||
const divider = screen.getByTestId('divider'); | ||
|
||
expect(divider).toHaveStyle('--margin-top: var(--size-spacing-xxs)'); | ||
expect(divider).toHaveStyle('--margin-right: var(--size-spacing-xs)'); | ||
expect(divider).toHaveStyle('--margin-bottom: var(--size-spacing-sm)'); | ||
expect(divider).toHaveStyle('--margin-left: var(--size-spacing-md)'); | ||
}); | ||
}); |
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,51 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { ComponentPropsWithoutRef } from 'react'; | ||
import { Divider } from './Divider'; | ||
import { Stack } from '../Stack/Stack'; | ||
|
||
export default { | ||
component: Divider, | ||
} satisfies Meta<typeof Divider>; | ||
|
||
type Props = ComponentPropsWithoutRef<typeof Divider>; | ||
|
||
const defaultArgs: Props = { | ||
border: 'gray', | ||
}; | ||
|
||
type Story = StoryObj<typeof Divider>; | ||
|
||
export const Default: Story = { | ||
render: (args) => <Divider {...args} />, | ||
args: defaultArgs, | ||
}; | ||
|
||
export const BorderVariants: Story = { | ||
render: () => { | ||
return ( | ||
<Stack spacing="md"> | ||
<Divider border="gray" /> | ||
<Divider border="primary" /> | ||
</Stack> | ||
); | ||
}, | ||
}; | ||
|
||
export const Margins: Story = { | ||
render: (args) => <Divider {...args} />, | ||
args: { | ||
...defaultArgs, | ||
mt: 'md', | ||
mr: 'lg', | ||
mb: 'xl', | ||
ml: 'xxl', | ||
}, | ||
}; | ||
|
||
export const Width: Story = { | ||
render: (args) => <Divider {...args} />, | ||
args: { | ||
...defaultArgs, | ||
width: '50%', | ||
}, | ||
}; |
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,48 @@ | ||
'use client'; | ||
|
||
import { clsx } from 'clsx'; | ||
import { forwardRef, type HTMLAttributes } from 'react'; | ||
import styles from './Divider.module.css'; | ||
import { MarginProps, WidthProps } from '../../types/style'; | ||
import { marginVariables, widthVariables } from '../../utils/style'; | ||
|
||
type AllowedHRAttributes = Omit<HTMLAttributes<HTMLHRElement>, 'className'>; | ||
|
||
type Props = { | ||
/** | ||
* ボーダーの種類 | ||
*/ | ||
border?: 'gray' | 'primary'; | ||
} & WidthProps & | ||
MarginProps & | ||
AllowedHRAttributes; | ||
|
||
export const Divider = forwardRef<HTMLHRElement, Props>( | ||
({ border = 'gray', m, mx, my, mt, mr, mb, ml, width, minWidth, maxWidth, ...rest }, ref) => { | ||
return ( | ||
<hr | ||
className={clsx(styles.divider, styles[border])} | ||
style={{ | ||
...marginVariables({ | ||
m, | ||
mx, | ||
my, | ||
mt, | ||
mr, | ||
mb, | ||
ml, | ||
}), | ||
...widthVariables({ | ||
width, | ||
minWidth, | ||
maxWidth, | ||
}), | ||
}} | ||
ref={ref} | ||
{...rest} | ||
/> | ||
); | ||
}, | ||
); | ||
|
||
Divider.displayName = 'Divider'; |
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
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
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