Skip to content

Commit d5a5b58

Browse files
committed
feat(alpha-icon): implement
1 parent bc4319e commit d5a5b58

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@use '../../styles/mixins/dimension';
2+
3+
$size-map: (
4+
xxxs: 10,
5+
xxs: 12,
6+
xs: 16,
7+
s: 20,
8+
m: 24,
9+
l: 36,
10+
xl: 44,
11+
);
12+
13+
.Icon {
14+
--b-icon-color: initial;
15+
16+
flex: 0 0 auto;
17+
color: var(--b-icon-color);
18+
transition: color var(--transition-s);
19+
20+
@each $size, $value in $size-map {
21+
&:where(.size-#{$size}) {
22+
@include dimension.square(#{$value}px);
23+
}
24+
}
25+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use client'
2+
3+
import { forwardRef, memo } from 'react'
4+
import * as React from 'react'
5+
6+
import classNames from 'classnames'
7+
8+
import { getMarginStyles, splitByMarginProps } from '~/src/types/props-helpers'
9+
import { alphaColorTokenCssVar } from '~/src/utils/style'
10+
11+
import { type IconProps } from './Icon.types'
12+
13+
import styles from './Icon.module.scss'
14+
15+
export const ICON_TEST_ID = 'bezier-alpha-icon'
16+
17+
export const Icon = memo(
18+
forwardRef<SVGSVGElement, IconProps>(function Icon(props, forwardedRef) {
19+
const [marginProps, marginRest] = splitByMarginProps(props)
20+
const marginStyles = getMarginStyles(marginProps)
21+
22+
const {
23+
className,
24+
size = 'm',
25+
color,
26+
source: SourceElement,
27+
style,
28+
...rest
29+
} = marginRest
30+
31+
return (
32+
<SourceElement
33+
ref={forwardedRef}
34+
style={
35+
{
36+
'--b-icon-color': alphaColorTokenCssVar(color),
37+
...marginStyles.style,
38+
...style,
39+
} as React.CSSProperties
40+
}
41+
className={classNames(
42+
styles.Icon,
43+
styles[`size-${size}`],
44+
marginStyles.className,
45+
className
46+
)}
47+
data-testid={ICON_TEST_ID}
48+
{...rest}
49+
/>
50+
)
51+
})
52+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { type BezierIcon } from '@channel.io/bezier-icons'
2+
3+
import type { FunctionalColor, SemanticColor } from '~/src/types/alpha-tokens'
4+
import {
5+
type BezierComponentProps,
6+
type MarginProps,
7+
type SizeProps,
8+
} from '~/src/types/props'
9+
10+
export type IconSize = 'xs' | 's' | 'm' | 'l' | 'xl'
11+
12+
interface IconOwnProps {
13+
/**
14+
* Controls which icon should be rendered.
15+
* Inject the icon component from the `@channel.io/bezier-icons` package into this prop.
16+
* @example
17+
* ```tsx
18+
* import { HeartFilledIcon } from '@channel.io/bezier-icons'
19+
* import { Icon } from '@channel.io/bezier-react'
20+
*
21+
* <Icon source={HeartFilledIcon} {...} />
22+
* ```
23+
*/
24+
source: BezierIcon
25+
/**
26+
* Color from the design system's functional or semantic color.
27+
*/
28+
color?: FunctionalColor | SemanticColor
29+
}
30+
31+
export interface IconProps
32+
extends Omit<BezierComponentProps<'svg'>, keyof IconOwnProps>,
33+
MarginProps,
34+
SizeProps<IconSize>,
35+
IconOwnProps {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { Icon as AlphaIcon } from './Icon'
2+
export type {
3+
IconProps as AlphaIconProps,
4+
IconSize as AlphaIconSize,
5+
} from './Icon.types'

packages/bezier-react/src/utils/style.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type * as AlphaTokens from '~/src/types/alpha-tokens'
12
import { type FlattenAllToken } from '~/src/types/tokens'
23
import { isNil, isString } from '~/src/utils/type'
34

@@ -59,3 +60,18 @@ export function tokenCssVar<PropertyName extends FlattenAllToken | undefined>(
5960
export function cssUrl(url?: string) {
6061
return isNil(url) ? undefined : `url(${url})`
6162
}
63+
64+
/**
65+
* TODO: (@ed) Implement
66+
*/
67+
export function alphaTokenCssVar<
68+
PropertyName extends AlphaTokens.FlattenAllToken | undefined,
69+
>(propertyName: PropertyName) {
70+
return cssVar(propertyName)
71+
}
72+
73+
export function alphaColorTokenCssVar<
74+
PropertyName extends AlphaTokens.BaseSemanticColor | undefined,
75+
>(propertyName: PropertyName) {
76+
return cssVar(`alpha-color-${propertyName}`)
77+
}

0 commit comments

Comments
 (0)