Skip to content

Commit 6f82412

Browse files
committed
feat: update eslint to restrict IconBase usage, IconBase - add color, tooltip and strokeWidth support
1 parent c9f8bd2 commit 6f82412

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

.eslintrc.cjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ module.exports = {
122122
{
123123
name: 'react-toastify',
124124
message: 'Please use "ToastManager.showToast" instead.',
125-
}
125+
},
126+
],
127+
patterns: [
128+
{
129+
group: ['IconBase'],
130+
message: 'Please use "Icon" component instead.',
131+
},
126132
],
127133
},
128134
],

scripts/generate-icon.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const generateIconComponent = () => {
5555
5656
${imports.join('\n')}
5757
58+
// eslint-disable-next-line no-restricted-imports
5859
import { IconBase } from './IconBase';
5960
import { IconBaseProps } from './types';
6061
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1+
import { ConditionalWrap } from '@Common/Helper'
2+
import { Tooltip } from '@Common/Tooltip'
3+
14
import { IconBaseProps } from './types'
25

3-
export const IconBase = ({ name, iconMap, size = 24 }: IconBaseProps) => {
6+
import './styles.scss'
7+
8+
const conditionalWrap = (tooltipProps: IconBaseProps['tooltipProps']) => (children: JSX.Element) => (
9+
<Tooltip {...tooltipProps}>
10+
<div className="flex">{children}</div>
11+
</Tooltip>
12+
)
13+
14+
export const IconBase = ({ name, iconMap, size = 16, tooltipProps, color, strokeWidth }: IconBaseProps) => {
415
const IconComponent = iconMap[name]
516

617
if (!IconComponent) {
718
throw new Error(`Icon with name "${name}" does not exist.`)
819
}
920

10-
return <IconComponent className={`icon-dim-${size}`} />
21+
return (
22+
<ConditionalWrap condition={!!tooltipProps?.content} wrap={conditionalWrap(tooltipProps)}>
23+
<IconComponent
24+
className={`icon-dim-${size} ${color ? 'icon-component' : ''} dc__no-shrink`}
25+
style={color ? { ['--iconColor' as string]: `var(--${color})` } : {}}
26+
strokeWidth={strokeWidth}
27+
/>
28+
</ConditionalWrap>
29+
)
1130
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.icon-component {
2+
&:not([data-style-override='false']) {
3+
:where([stroke^='#']:not([data-style-override='false'])) {
4+
stroke: var(--iconColor);
5+
}
6+
:where([fill^='#']:not([data-style-override='false'])) {
7+
fill: var(--iconColor);
8+
}
9+
}
10+
}

src/Shared/Components/Icon/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { FC, SVGProps } from 'react'
1+
import { FC, SVGAttributes, SVGProps } from 'react'
2+
3+
import { TooltipProps } from '@Common/Tooltip/types'
24

35
type IconMap = Record<string, FC<SVGProps<SVGSVGElement>>>
46

5-
export interface IconBaseProps {
7+
export interface IconBaseProps extends Pick<SVGAttributes<SVGSVGElement>, 'strokeWidth'> {
68
name: keyof IconMap
79
iconMap: IconMap
810
size?: 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 28 | 30 | 32 | 34 | 36 | 40 | 42 | 44 | 48 | 72 | 80
11+
tooltipProps?: TooltipProps
12+
color: `${'B' | 'N' | 'G' | 'Y' | 'R' | 'V' | 'O'}${`${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}00` | '50'}` | null
913
}

0 commit comments

Comments
 (0)