-
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
AlphaIcon
component
#2566
Open
sungik-choi
wants to merge
18
commits into
channel-io:main
Choose a base branch
from
sungik-choi:web-4647-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
AlphaIcon
component
#2566
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
74790ef
feat(alpha-icon): implement
sungik-choi abc9553
feat(alpha-icon): export modules
sungik-choi 85458b9
feat(bezier-tokens): add alpha source-size dimension tokens
sungik-choi de3980b
feat: add SourceSize type
sungik-choi c0cc4aa
fix(vscode): exclude source-size tokens from the suggestion group
sungik-choi 82175b4
feat: add classnames & props helpers
sungik-choi e771a36
feat(components): apply the new alpha source size style to related co…
sungik-choi 9eed83a
test: update snapshot
sungik-choi 09b80ce
refactor: rm comment
sungik-choi 579a95f
refactor: get source size classnames via scss map
sungik-choi 78961c2
feat: add AlphaIcon stories
sungik-choi 0512740
refactor: rm test id
sungik-choi 547f3d9
docs: add jsdoc
sungik-choi a95ede7
feat(icon): enhance a11y
sungik-choi 2bf0713
feat(icon-button): use AlphaIcon instead of Icon
sungik-choi 8eb5c3d
test: add unit test
sungik-choi cbdccfc
chore: add changeset
sungik-choi 125c175
chore: add changeset
sungik-choi 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-tokens': patch | ||
--- | ||
|
||
Add source size tokens |
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 `AlphaIcon` component |
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
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
66 changes: 66 additions & 0 deletions
66
packages/bezier-react/src/components/AlphaIcon/AlphaIcon.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,66 @@ | ||
import { | ||
ChannelBtnFilledIcon, | ||
type IconName, | ||
icons, | ||
} from '@channel.io/bezier-icons' | ||
import { type Meta, type StoryObj } from '@storybook/react' | ||
|
||
import { camelCase } from '~/src/utils/string' | ||
|
||
import { AlphaIconButton } from '~/src/components/AlphaIconButton' | ||
import { Stack } from '~/src/components/Stack' | ||
import { Tooltip } from '~/src/components/Tooltip' | ||
|
||
import { Icon } from './Icon' | ||
import { type IconProps } from './Icon.types' | ||
|
||
const meta: Meta<typeof Icon> = { | ||
component: Icon, | ||
} | ||
|
||
export default meta | ||
|
||
export const Primary: StoryObj<IconProps> = { | ||
args: { | ||
source: ChannelBtnFilledIcon, | ||
size: '24', | ||
color: 'fg-black-darker', | ||
}, | ||
} | ||
|
||
const pascalCase = (str: string) => | ||
camelCase(str).replace(/^./, (char) => char.toUpperCase()) | ||
|
||
const iconNames = Object.keys(icons) as IconName[] | ||
|
||
export const IconGallery: StoryObj = { | ||
render: () => ( | ||
<Stack | ||
direction="horizontal" | ||
wrap | ||
spacing={16} | ||
padding={16} | ||
> | ||
{iconNames.map((iconName) => ( | ||
<Stack | ||
key={iconName} | ||
direction="vertical" | ||
align="center" | ||
spacing={4} | ||
width={40} | ||
height={40} | ||
borderRadius="6" | ||
> | ||
<Tooltip content={pascalCase(iconName)}> | ||
<AlphaIconButton | ||
size="m" | ||
content={icons[iconName]} | ||
variant="tertiary" | ||
color="dark-grey" | ||
/> | ||
</Tooltip> | ||
</Stack> | ||
))} | ||
</Stack> | ||
), | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/bezier-react/src/components/AlphaIcon/Icon.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,7 @@ | ||
.Icon { | ||
--b-icon-color: initial; | ||
|
||
flex: 0 0 auto; | ||
color: var(--b-icon-color); | ||
transition: color var(--transition-s); | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/bezier-react/src/components/AlphaIcon/Icon.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,43 @@ | ||
import { ChannelBtnFilledIcon } from '@channel.io/bezier-icons' | ||
import { render, screen } from '@testing-library/react' | ||
|
||
import { Icon } from './Icon' | ||
|
||
describe('Icon', () => { | ||
const renderIcon = (props = {}) => | ||
render( | ||
<Icon | ||
source={ChannelBtnFilledIcon} | ||
{...props} | ||
/> | ||
) | ||
|
||
it('should render', () => { | ||
renderIcon() | ||
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument() | ||
}) | ||
|
||
describe('Accessibility', () => { | ||
it('should be decorative by default', () => { | ||
renderIcon() | ||
expect(screen.getByRole('img', { hidden: true })).toHaveAttribute( | ||
'aria-hidden', | ||
'true' | ||
) | ||
}) | ||
|
||
it('should be accessible with aria-label', () => { | ||
renderIcon({ 'aria-label': 'Channel Button' }) | ||
expect(screen.getByRole('img')).toHaveAttribute( | ||
'aria-label', | ||
'Channel Button' | ||
) | ||
expect(screen.getByRole('img')).toBeInTheDocument() | ||
}) | ||
|
||
it('should respect explicit aria-hidden', () => { | ||
renderIcon({ 'aria-hidden': false }) | ||
expect(screen.getByRole('img')).toBeInTheDocument() | ||
}) | ||
}) | ||
}) |
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,71 @@ | ||
'use client' | ||
|
||
import { forwardRef, memo } from 'react' | ||
import * as React from 'react' | ||
|
||
import classNames from 'classnames' | ||
|
||
import { getSourceSizeClassName } from '~/src/types/alpha-props-helpers' | ||
import { getMarginStyles, splitByMarginProps } from '~/src/types/props-helpers' | ||
import { alphaColorTokenCssVar } from '~/src/utils/style' | ||
|
||
import { type IconProps } from './Icon.types' | ||
|
||
import styles from './Icon.module.scss' | ||
|
||
/** | ||
* `Icon` is a component that renders SVG icons from "@channel.io/bezier-icons" | ||
* @example | ||
* ```tsx | ||
* import { ChannelBtnFilledIcon } from '@channel.io/bezier-icons' | ||
* | ||
* <Icon | ||
* source={ChannelBtnFilledIcon} | ||
* size="24" | ||
* color="fg-black-darker" | ||
* /> | ||
* ``` | ||
*/ | ||
export const Icon = memo( | ||
forwardRef<SVGSVGElement, IconProps>(function Icon(props, forwardedRef) { | ||
const [marginProps, marginRest] = splitByMarginProps(props) | ||
const marginStyles = getMarginStyles(marginProps) | ||
|
||
const { | ||
className, | ||
size = '24', | ||
color, | ||
source: SourceElement, | ||
style, | ||
'aria-hidden': ariaHidden, | ||
'aria-label': ariaLabel, | ||
role = 'img', | ||
...rest | ||
} = marginRest | ||
|
||
const isDecorative = !ariaLabel && ariaHidden !== false | ||
|
||
return ( | ||
<SourceElement | ||
ref={forwardedRef} | ||
role={role} | ||
aria-hidden={isDecorative} | ||
aria-label={ariaLabel} | ||
style={ | ||
{ | ||
'--b-icon-color': alphaColorTokenCssVar(color), | ||
...marginStyles.style, | ||
...style, | ||
} as React.CSSProperties | ||
} | ||
className={classNames( | ||
styles.Icon, | ||
getSourceSizeClassName(size), | ||
marginStyles.className, | ||
className | ||
)} | ||
{...rest} | ||
/> | ||
) | ||
}) | ||
) |
Oops, something went wrong.
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.
테스트 시 구체적으로 높이를 지정하지 않아도 잘 동작함