-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/master' into HEAD
- Loading branch information
Showing
15 changed files
with
708 additions
and
552 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
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,69 @@ | ||
import React, { act } from 'react' | ||
import { createRoot } from 'react-dom/client' | ||
|
||
import { Button } from './Button' | ||
|
||
describe('Button', () => { | ||
let container: HTMLDivElement | ||
beforeEach(() => { | ||
container = document.createElement('div') | ||
document.body.appendChild(container) | ||
}) | ||
afterEach(() => { | ||
document.body.removeChild(container) | ||
}) | ||
|
||
describe('onClick', () => { | ||
it('disabled / loading でない場合、発火する', () => { | ||
const onClick = jest.fn() | ||
act(() => { | ||
createRoot(container).render(<Button onClick={onClick}>button</Button>) | ||
}) | ||
document.querySelector('button')!.click() | ||
expect(onClick).toHaveBeenCalled() | ||
}) | ||
|
||
it('disabled / loading の場合、発火しない', () => { | ||
const onClick = jest.fn() | ||
act(() => { | ||
createRoot(container).render( | ||
<Button onClick={onClick} disabled> | ||
button | ||
</Button>, | ||
) | ||
}) | ||
document.querySelector('button')!.click() | ||
expect(onClick).not.toHaveBeenCalled() | ||
}) | ||
|
||
describe('form 要素でラップされている場合', () => { | ||
it('disabled / loading でない場合、発火しない', () => { | ||
const onSubmit = jest.fn() | ||
act(() => { | ||
createRoot(container).render( | ||
<form onSubmit={onSubmit}> | ||
<Button type="submit">button</Button> | ||
</form>, | ||
) | ||
}) | ||
document.querySelector('button')!.click() | ||
expect(onSubmit).toHaveBeenCalled() | ||
}) | ||
|
||
it('disabled / loading の場合、発火しない', () => { | ||
const onSubmit = jest.fn() | ||
act(() => { | ||
createRoot(container).render( | ||
<form onSubmit={onSubmit}> | ||
<Button type="submit" loading> | ||
button | ||
</Button> | ||
</form>, | ||
) | ||
}) | ||
document.querySelector('button')!.click() | ||
expect(onSubmit).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
}) | ||
}) |
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
43 changes: 43 additions & 0 deletions
43
packages/smarthr-ui/src/components/UpwardLink/UpwardLink.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,43 @@ | ||
import React, { useCallback } from 'react' | ||
|
||
import { Fieldset } from '../Fieldset' | ||
import { PageHeading } from '../Heading' | ||
import { Cluster, Stack } from '../Layout' | ||
import { RadioButton } from '../RadioButton' | ||
|
||
import { UpwardLink } from './UpwardLink' | ||
|
||
import type { StoryFn, StoryObj } from '@storybook/react/*' | ||
|
||
export default { | ||
title: 'Navigation(ナビゲーション)/TextLink', | ||
component: UpwardLink, | ||
} | ||
|
||
const Template: StoryFn = (args) => <UpwardLink {...args} href="/" /> | ||
|
||
export const Default: StoryObj = { | ||
name: 'UpwardLink', | ||
render: () => { | ||
const [indent, setIndent] = React.useState(true) | ||
const handleChange = useCallback(() => setIndent(!indent), [indent]) | ||
return ( | ||
<Stack> | ||
<Fieldset title="インデント"> | ||
<Cluster gap={1}> | ||
<RadioButton name="indent" onChange={handleChange} checked={indent}> | ||
あり | ||
</RadioButton> | ||
<RadioButton name="indent" onChange={handleChange} checked={!indent}> | ||
なし | ||
</RadioButton> | ||
</Cluster> | ||
</Fieldset> | ||
<Stack className="shr-bg-background shr-p-2"> | ||
<Template indent={indent}>権限一覧に戻る</Template> | ||
<PageHeading>権限詳細</PageHeading> | ||
</Stack> | ||
</Stack> | ||
) | ||
}, | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/smarthr-ui/src/components/UpwardLink/UpwardLink.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,28 @@ | ||
import React, { type ComponentProps } from 'react' | ||
import { VariantProps, tv } from 'tailwind-variants' | ||
|
||
import { FaArrowLeftIcon } from '../Icon' | ||
import { TextLink } from '../TextLink' | ||
|
||
const upwardLink = tv({ | ||
base: 'shr-leading-none', | ||
variants: { | ||
indent: { | ||
true: '-shr-translate-x-1.25', | ||
false: '', | ||
}, | ||
}, | ||
}) | ||
|
||
type Props = Omit<ComponentProps<typeof TextLink>, 'prefix' | 'suffix'> & | ||
VariantProps<typeof upwardLink> | ||
|
||
export const UpwardLink: React.FC<Props> = ({ indent = true, className, ...rest }) => { | ||
const style = upwardLink({ indent, className }) | ||
return ( | ||
<div className={style}> | ||
{/* eslint-disable-next-line smarthr/a11y-anchor-has-href-attribute */} | ||
<TextLink {...rest} prefix={<FaArrowLeftIcon />} /> | ||
</div> | ||
) | ||
} |
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 { UpwardLink } from './UpwardLink' |
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
Oops, something went wrong.