Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 1, 2024
2 parents 26f5c65 + 53775fb commit 464244c
Show file tree
Hide file tree
Showing 35 changed files with 1,113 additions and 1,036 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ on:
pull_request:
branches:
- master
pull_request_review:
types: [submitted]

jobs:
e2e-win-matrix:
if: ${{ (((github.event_name != 'pull_request_review') && !(startsWith(github.event.pull_request.head.ref, 'merge-release-'))) || (github.event_name == 'pull_request_review') && (startsWith(github.event.pull_request.head.ref, 'merge-release-'))) }}
runs-on: windows-latest
timeout-minutes: 30
strategy:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/previewRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ name: Preview Release
on:
pull_request:
types: [opened, reopened, synchronize]
pull_request_review:
types: [submitted]

jobs:
previewRelease:
if: ${{ (((github.event_name != 'pull_request_review') && !(startsWith(github.event.pull_request.head.ref, 'merge-release-'))) || (github.event_name == 'pull_request_review') && (startsWith(github.event.pull_request.head.ref, 'merge-release-'))) }}
runs-on: ubuntu-latest

steps:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/titleCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ name: PR Title Check
on:
pull_request:
types: [opened, edited, synchronize, reopened]
pull_request_review:
types: [submitted]

jobs:
conventional_commits:
if: ${{ (((github.event_name != 'pull_request_review') && !(startsWith(github.event.pull_request.head.ref, 'merge-release-'))) || (github.event_name == 'pull_request_review') && (startsWith(github.event.pull_request.head.ref, 'merge-release-'))) }}
runs-on: ubuntu-latest
steps:
- name: check title
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@commitlint/config-conventional": "^19.5.0",
"eslint": "^8.57.0",
"eslint-config-smarthr": "^6.33.2",
"eslint-plugin-storybook": "^0.8.0",
"eslint-plugin-storybook": "^0.9.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
Expand All @@ -31,7 +31,7 @@
"pnpm": {
"overrides": {
"@babel/helper-compilation-targets": "^7.25.2",
"@types/react": "^18.3.8",
"@types/react": "^18.3.10",
"minimist": "1.2.8",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
3 changes: 0 additions & 3 deletions packages/smarthr-ui/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ const config: StorybookConfig = {
options: {},
},
staticDirs: ['../public'],
docs: {
autodocs: true,
},
typescript: {
reactDocgen: 'react-docgen-typescript',
},
Expand Down
4 changes: 4 additions & 0 deletions packages/smarthr-ui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ const preview: Preview = {
<Stories includePrimary={false} />
</>
),
canvas: {
sourceState: 'shown',
},
},
chromatic: {
forcedColors: 'none',
Expand Down Expand Up @@ -102,6 +105,7 @@ const preview: Preview = {
)
},
],
tags: ['autodocs'],
}

export default preview
Expand Down
40 changes: 0 additions & 40 deletions packages/smarthr-ui/e2e/components/Calendar.test.ts

This file was deleted.

42 changes: 21 additions & 21 deletions packages/smarthr-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,46 @@
"@babel/preset-env": "^7.25.4",
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@storybook/addon-a11y": "^8.3.2",
"@storybook/addon-actions": "^8.3.2",
"@storybook/addon-essentials": "^8.3.2",
"@storybook/addon-interactions": "^8.3.2",
"@storybook/addon-storysource": "^8.3.2",
"@storybook/addon-a11y": "^8.3.4",
"@storybook/addon-actions": "^8.3.4",
"@storybook/addon-essentials": "^8.3.4",
"@storybook/addon-interactions": "^8.3.4",
"@storybook/addon-storysource": "^8.3.4",
"@storybook/addon-styling": "^1.3.7",
"@storybook/addon-styling-webpack": "^1.0.0",
"@storybook/addon-viewport": "^8.3.2",
"@storybook/addon-viewport": "^8.3.4",
"@storybook/addon-webpack5-compiler-babel": "^3.0.3",
"@storybook/blocks": "^8.3.2",
"@storybook/cli": "^8.3.2",
"@storybook/manager-api": "^8.3.2",
"@storybook/react": "^8.3.2",
"@storybook/react-webpack5": "^8.3.2",
"@storybook/source-loader": "^8.3.2",
"@storybook/test": "^8.3.2",
"@storybook/blocks": "^8.3.4",
"@storybook/cli": "^8.3.4",
"@storybook/manager-api": "^8.3.4",
"@storybook/react": "^8.3.4",
"@storybook/react-webpack5": "^8.3.4",
"@storybook/source-loader": "^8.3.4",
"@storybook/test": "^8.3.4",
"@storybook/test-runner": "^0.19.1",
"@storybook/theming": "^8.3.2",
"@storybook/theming": "^8.3.4",
"@swc/core": "^1.7.26",
"@testing-library/react": "^16.0.1",
"@types/lodash.merge": "^4.6.9",
"@types/lodash.range": "^3.2.9",
"@types/node": "^20.16.5",
"@types/react": "^18.3.8",
"@types/node": "^20.16.10",
"@types/react": "^18.3.10",
"@types/react-dom": "^18.3.0",
"@types/react-test-renderer": "^17.0.9",
"@types/react-transition-group": "^4.4.11",
"@types/styled-components": "^5.1.34",
"autoprefixer": "^10.4.20",
"axe-playwright": "^2.0.2",
"axe-playwright": "^2.0.3",
"babel-loader": "^9.2.1",
"babel-plugin-polyfill-corejs2": "^0.4.11",
"babel-plugin-polyfill-regenerator": "^0.6.2",
"css-loader": "^7.1.2",
"chromatic": "^11.10.2",
"chromatic": "^11.10.4",
"ecma-version-validator-webpack-plugin": "^1.2.1",
"fs-extra": "^11.2.0",
"glob": "11.0.0",
"http-server": "^14.1.1",
"jsdom": "^25.0.0",
"jsdom": "^25.0.1",
"memory-fs": "^0.5.0",
"npm-run-all": "^4.1.5",
"playwright": "^1.47.2",
Expand All @@ -75,7 +75,7 @@
"react-test-renderer": "^18.3.1",
"rimraf": "^6.0.1",
"standard-version": "^9.3.2",
"storybook": "^8.3.2",
"storybook": "^8.3.4",
"storybook-addon-pseudo-states": "^4.0.2",
"style-loader": "^4.0.0",
"styled-components": "^5.3.11",
Expand All @@ -85,7 +85,7 @@
"typescript-plugin-styled-components": "^3.0.0",
"vitest": "^2.1.1",
"wait-on": "^8.0.1",
"webpack": "^5.94.0"
"webpack": "^5.95.0"
},
"peerDependencies": {
"react": "^18.0.0",
Expand Down
89 changes: 63 additions & 26 deletions packages/smarthr-ui/src/components/AppNavi/AppNaviAnchor.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
import React, { FC, PropsWithChildren, useMemo } from 'react'
import React, {
ComponentPropsWithoutRef,
ComponentType,
ElementType,
FC,
PropsWithoutRef,
ReactElement,
Ref,
forwardRef,
useMemo,
} from 'react'
import { tv } from 'tailwind-variants'

import { ElementRef, ElementRefProps } from '../../types'
import { ComponentProps as IconProps } from '../Icon'

import { appNaviItemStyle } from './style'

export type AppNaviAnchorProps = PropsWithChildren<{
type ElementProps<T extends ElementType> = Omit<
ComponentPropsWithoutRef<T>,
keyof AppNaviAnchorProps<T> & ElementRefProps<T>
>

export type AppNaviAnchorProps<T extends ElementType = 'a'> = {
/** アンカーの href */
href: string
href?: string
/** 表示するアイコンタイプ */
icon?: React.ComponentType<IconProps>
icon?: ComponentType<IconProps>
/** アクティブ状態であるかどうか */
current?: boolean
}>
/** next/link などのカスタムコンポーネントを指定します。指定がない場合はデフォルトで `a` タグが使用されます。 */
elementAs?: T
}

type AppNaviAnchorComponent = <T extends ElementType = 'a'>(
props: AppNaviAnchorProps<T> & ElementProps<T> & ElementRefProps<T>,
) => ReturnType<FC>

const appNaviAnchor = tv({
extend: appNaviItemStyle,
Expand All @@ -21,24 +43,39 @@ const appNaviAnchor = tv({
},
})

export const AppNaviAnchor: FC<AppNaviAnchorProps> = ({
children,
href,
icon: Icon,
current = false,
}) => {
const { wrapperStyle, iconStyle } = useMemo(() => {
const { wrapper, icon } = appNaviAnchor({ active: current })
return {
wrapperStyle: wrapper(),
iconStyle: icon(),
}
}, [current])

return (
<a aria-current={current ? 'page' : undefined} href={href} className={wrapperStyle}>
{Icon && <Icon className={iconStyle} />}
{children}
</a>
)
}
export const AppNaviAnchor: AppNaviAnchorComponent = forwardRef(
<T extends ElementType = 'a'>(
{
children,
href,
icon: Icon,
current = false,
elementAs,
...others
}: PropsWithoutRef<AppNaviAnchorProps<T>> & ElementProps<T>,
ref: Ref<ElementRef<T>>,
): ReactElement => {
const { wrapperStyle, iconStyle } = useMemo(() => {
const { wrapper, icon } = appNaviAnchor({ active: current })
return {
wrapperStyle: wrapper(),
iconStyle: icon(),
}
}, [current])

const Component = elementAs || 'a'

return (
<Component
{...others}
ref={ref}
href={href}
aria-current={current ? 'page' : undefined}
className={wrapperStyle}
>
{Icon && <Icon className={iconStyle} />}
{children}
</Component>
)
},
)
48 changes: 48 additions & 0 deletions packages/smarthr-ui/src/components/Calendar/Calendar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { render, screen } from '@testing-library/react'
import React, { act } from 'react'

import { Calendar } from './Calendar'

describe('Calendar', () => {
it('value で指定した日付が選択されていること', () => {
render(<Calendar value={new Date(2020, 0, 15)} onSelectDate={vi.fn()} />)

expect(screen.queryByText('2020年1月')).toBeTruthy()
expect(screen.getByRole('button', { name: '15' }).getAttribute('aria-pressed')).toBe('true')
})

it('前の月に切り替えることができる', () => {
render(<Calendar value={new Date(2020, 1, 15)} onSelectDate={vi.fn()} />)

act(() => screen.getByRole('button', { name: '前の月へ' }).click())
expect(screen.queryByText('2020年1月')).toBeTruthy()

act(() => screen.getByRole('button', { name: '前の月へ' }).click())
expect(screen.queryByText('2019年12月')).toBeTruthy()
})

it('次の月に切り替えることができる', () => {
render(<Calendar value={new Date(2020, 10, 15)} onSelectDate={vi.fn()} />)

act(() => screen.getByRole('button', { name: '次の月へ' }).click())
expect(screen.queryByText('2020年12月')).toBeTruthy()

act(() => screen.getByRole('button', { name: '次の月へ' }).click())
expect(screen.queryByText('2021年1月')).toBeTruthy()
})

it('年を切り替えることができる', () => {
render(<Calendar value={new Date(2020, 10, 15)} onSelectDate={vi.fn()} />)

act(() => screen.getByRole('button', { name: '年を選択する' }).click())
act(() => screen.getByRole('button', { name: '2024' }).click())
expect(screen.queryByText('2024年11月')).toBeTruthy()
})

it('日にちを選択すると、onSelectDate が発火すること', () => {
const onSelectDate = vi.fn()
render(<Calendar value={new Date(2021, 8, 20)} onSelectDate={onSelectDate} />)
act(() => screen.getByRole('button', { name: '10' }).click())
expect(onSelectDate).toHaveBeenCalledWith(expect.anything(), new Date(2021, 8, 10))
})
})
Loading

0 comments on commit 464244c

Please sign in to comment.