File tree Expand file tree Collapse file tree 5 files changed +133
-0
lines changed
packages/bezier-react/src Expand file tree Collapse file tree 5 files changed +133
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ )
Original file line number Diff line number Diff line change
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 { }
Original file line number Diff line number Diff line change
1
+ export { Icon as AlphaIcon } from './Icon'
2
+ export type {
3
+ IconProps as AlphaIconProps ,
4
+ IconSize as AlphaIconSize ,
5
+ } from './Icon.types'
Original file line number Diff line number Diff line change
1
+ import type * as AlphaTokens from '~/src/types/alpha-tokens'
1
2
import { type FlattenAllToken } from '~/src/types/tokens'
2
3
import { isNil , isString } from '~/src/utils/type'
3
4
@@ -59,3 +60,18 @@ export function tokenCssVar<PropertyName extends FlattenAllToken | undefined>(
59
60
export function cssUrl ( url ?: string ) {
60
61
return isNil ( url ) ? undefined : `url(${ url } )`
61
62
}
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
+ }
You can’t perform that action at this time.
0 commit comments