-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AlphaSpinner
component
#2237
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ad688dc
feat(spinner): implement `AlphaSpinner` component
yangwooseong cc7b751
feat(spinner): test and storybook
yangwooseong 2471584
feat(spinner): export
yangwooseong 0c7fc76
chore(changeset): add
yangwooseong c3ff185
refactor(spinner): change classname according to figma
yangwooseong 7b9f34a
feat(spinner): make size optional
yangwooseong f398398
feat(spinner): change variable name to indicator
yangwooseong 4682f95
fix(spinner): typo fix
yangwooseong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,5 @@ | ||
--- | ||
"@channel.io/bezier-react": patch | ||
--- | ||
|
||
Add `AlphaSpinner` component |
23 changes: 23 additions & 0 deletions
23
packages/bezier-react/src/components/AlphaSpinner/AlphaSpinner.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,23 @@ | ||
import React from 'react' | ||
|
||
import { type Meta, type StoryFn } from '@storybook/react' | ||
|
||
import { Spinner } from './Spinner' | ||
import { type SpinnerProps } from './Spinner.types' | ||
|
||
const meta: Meta<typeof Spinner> = { | ||
component: Spinner, | ||
} | ||
|
||
export default meta | ||
|
||
const Template: StoryFn<SpinnerProps> = ({ ...args }) => <Spinner {...args} /> | ||
|
||
export const Primary = { | ||
render: Template, | ||
|
||
args: { | ||
size: 'm', | ||
variant: 'secondary', | ||
}, | ||
} |
66 changes: 66 additions & 0 deletions
66
packages/bezier-react/src/components/AlphaSpinner/Spinner.module.scss
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,66 @@ | ||
@use '../../styles/mixins/dimension'; | ||
|
||
@keyframes rotate { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
|
||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
.Spinner { | ||
--b-spinner-size: initial; | ||
--b-spinner-track-color: initial; | ||
--b-spinner-indicator-color: initial; | ||
--b-spinner-stroke-width: initial; | ||
--b-spinner-stroke-dasharray: initial; | ||
|
||
@include dimension.square(var(--b-spinner-size)); | ||
|
||
display: inline-flex; | ||
animation: rotate 1s linear infinite; | ||
|
||
& .track { | ||
fill: none; | ||
stroke: var(--b-spinner-track-color); | ||
stroke-linecap: round; | ||
stroke-width: var(--b-spinner-stroke-width); | ||
} | ||
|
||
& .indicator { | ||
fill: none; | ||
stroke: var(--b-spinner-indicator-color); | ||
stroke-dasharray: var(--b-spinner-stroke-dasharray); | ||
stroke-linecap: round; | ||
stroke-width: var(--b-spinner-stroke-width); | ||
} | ||
|
||
&:where(.size-s) { | ||
--b-spinner-size: 28px; | ||
--b-spinner-stroke-width: 4px; | ||
--b-spinner-stroke-dasharray: 40 9999; | ||
} | ||
|
||
&:where(.size-m) { | ||
--b-spinner-size: 50px; | ||
--b-spinner-stroke-width: 6px; | ||
--b-spinner-stroke-dasharray: 60 9999; | ||
} | ||
|
||
&:where(.variant-primary) { | ||
--b-spinner-track-color: var(--alpha-color-primary-bg-lightest); | ||
--b-spinner-indicator-color: var(--alpha-color-fg-blue-normal); | ||
} | ||
|
||
&:where(.variant-secondary) { | ||
--b-spinner-track-color: var(--alpha-color-bg-black-light); | ||
--b-spinner-indicator-color: var(--alpha-color-fg-black-light); | ||
} | ||
|
||
&:where(.variant-on-overlay) { | ||
--b-spinner-track-color: var(--alpha-color-bg-absolute-white-lightest); | ||
--b-spinner-indicator-color: var(--alpha-color-fg-absolute-white-light); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/bezier-react/src/components/AlphaSpinner/Spinner.test.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,34 @@ | ||
import React from 'react' | ||
|
||
import { render } from '~/src/utils/test' | ||
|
||
import { SPINNER_TEST_ID, Spinner } from './Spinner' | ||
|
||
describe('Spinner >', () => { | ||
const renderSpinner = (props?: React.ComponentProps<typeof Spinner>) => | ||
render(<Spinner {...props} />) | ||
|
||
it('should render', () => { | ||
const { getByTestId } = renderSpinner() | ||
const renderedSpinner = getByTestId(SPINNER_TEST_ID) | ||
expect(renderedSpinner).toBeInTheDocument() | ||
}) | ||
|
||
it('should render as a span element by default', () => { | ||
const { getByTestId } = renderSpinner() | ||
const renderedSpinner = getByTestId(SPINNER_TEST_ID) | ||
expect(renderedSpinner.tagName).toBe('SPAN') | ||
}) | ||
|
||
it('should forward ref', () => { | ||
const ref = React.createRef<HTMLDivElement>() | ||
renderSpinner({ ref }) | ||
expect(ref.current).toBeInTheDocument() | ||
}) | ||
|
||
it('should receive size', () => { | ||
const { getByTestId } = renderSpinner({ size: 'm' }) | ||
const renderedSpinner = getByTestId(SPINNER_TEST_ID) | ||
expect(renderedSpinner).toHaveClass('size-m') | ||
}) | ||
}) |
50 changes: 50 additions & 0 deletions
50
packages/bezier-react/src/components/AlphaSpinner/Spinner.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,50 @@ | ||
import React, { forwardRef } from 'react' | ||
|
||
import classNames from 'classnames' | ||
|
||
import { type SpinnerProps } from './Spinner.types' | ||
|
||
import styles from './Spinner.module.scss' | ||
|
||
export const SPINNER_TEST_ID = 'bezier-spinner' | ||
|
||
export const Spinner = forwardRef<HTMLSpanElement, SpinnerProps>( | ||
function Spinner( | ||
{ className, size, variant = 'secondary', ...rest }, | ||
forwardedRef | ||
) { | ||
return ( | ||
<span | ||
className={classNames( | ||
styles.Spinner, | ||
size && styles[`size-${size}`], | ||
styles[`variant-${variant}`] | ||
)} | ||
ref={forwardedRef} | ||
data-testid={SPINNER_TEST_ID} | ||
{...rest} | ||
> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 16 16" | ||
> | ||
<circle | ||
cx="8" | ||
cy="8" | ||
r="7" | ||
className={styles.track} | ||
vectorEffect="non-scaling-stroke" | ||
/> | ||
|
||
<circle | ||
cx="8" | ||
cy="8" | ||
r="7" | ||
className={styles.indicator} | ||
vectorEffect="non-scaling-stroke" | ||
/> | ||
</svg> | ||
</span> | ||
) | ||
} | ||
) |
21 changes: 21 additions & 0 deletions
21
packages/bezier-react/src/components/AlphaSpinner/Spinner.types.ts
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,21 @@ | ||
import { | ||
type BezierComponentProps, | ||
type ColorProps, | ||
type SizeProps, | ||
} from '~/src/types/props' | ||
|
||
type SpinnerSize = 's' | 'm' | ||
|
||
interface SpinnerOwnProps { | ||
/** | ||
* The style variant of Spinner. | ||
* @default 'secondary' | ||
*/ | ||
variant?: 'primary' | 'secondary' | 'on-overlay' | ||
} | ||
|
||
export interface SpinnerProps | ||
extends Omit<BezierComponentProps<'span'>, keyof ColorProps>, | ||
SizeProps<SpinnerSize>, | ||
ColorProps, | ||
SpinnerOwnProps {} |
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,2 @@ | ||
export { Spinner as AlphaSpinner } from './Spinner' | ||
export { type SpinnerProps as AlphaSpinnerProps } from './Spinner.types' |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
깔끔하네요 👍