Skip to content

Commit 51d31f3

Browse files
authored
Merge pull request #635 from devtron-labs/feat/icon-stroke-width
feat: Icon - remove strokeWidth prop, add dynamic stroke-width based on size
2 parents c1d0a55 + 43484eb commit 51d31f3

File tree

7 files changed

+28
-11
lines changed

7 files changed

+28
-11
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.9.5",
3+
"version": "1.9.6",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/DeleteCINodeButton/DeleteCINodeButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const DeleteCINodeButton = ({
100100
showAriaLabelInTippy
101101
onClick={onClickDeleteShowModal}
102102
style={ButtonStyleType.negativeGrey}
103-
icon={<Icon name="ic-delete" color={null} strokeWidth={1} size={12} />}
103+
icon={<Icon name="ic-delete" color={null} size={12} />}
104104
disabled={disabled}
105105
showTooltip
106106
tooltipProps={{

src/Shared/Components/Icon/IconBase.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ConditionalWrap } from '@Common/Helper'
1818
import { Tooltip } from '@Common/Tooltip'
1919

2020
import { IconBaseProps } from './types'
21+
import { ICON_STROKE_WIDTH_MAP } from './constants'
2122

2223
import './styles.scss'
2324

@@ -27,7 +28,7 @@ const conditionalWrap = (tooltipProps: IconBaseProps['tooltipProps']) => (childr
2728
</Tooltip>
2829
)
2930

30-
export const IconBase = ({ name, iconMap, size = 16, tooltipProps, color, strokeWidth }: IconBaseProps) => {
31+
export const IconBase = ({ name, iconMap, size = 16, tooltipProps, color }: IconBaseProps) => {
3132
const IconComponent = iconMap[name]
3233

3334
if (!IconComponent) {
@@ -37,9 +38,13 @@ export const IconBase = ({ name, iconMap, size = 16, tooltipProps, color, stroke
3738
return (
3839
<ConditionalWrap condition={!!tooltipProps?.content} wrap={conditionalWrap(tooltipProps)}>
3940
<IconComponent
40-
className={`icon-dim-${size} ${color ? 'icon-component' : ''} dc__no-shrink`}
41-
style={color ? { ['--iconColor' as string]: `var(--${color})` } : {}}
42-
strokeWidth={strokeWidth}
41+
className={`icon-dim-${size} ${color ? 'icon-component-color' : ''} ${ICON_STROKE_WIDTH_MAP[size] ? 'icon-component-stroke-width' : ''} dc__no-shrink`}
42+
style={{
43+
...(color ? { ['--iconColor' as string]: `var(--${color})` } : {}),
44+
...(ICON_STROKE_WIDTH_MAP[size]
45+
? { ['--strokeWidth' as string]: ICON_STROKE_WIDTH_MAP[size] }
46+
: {}),
47+
}}
4348
/>
4449
</ConditionalWrap>
4550
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { IconBaseProps } from './types'
2+
3+
export const ICON_STROKE_WIDTH_MAP: Partial<Record<IconBaseProps['size'], number>> = {
4+
'10': 1,
5+
'12': 1,
6+
}

src/Shared/Components/Icon/styles.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
.icon-component {
17+
.icon-component-color {
1818
&:not([data-style-override='false']) {
1919
:where([stroke^='#']:not([data-style-override='false'])) {
2020
stroke: var(--iconColor);
@@ -24,3 +24,9 @@
2424
}
2525
}
2626
}
27+
28+
.icon-component-stroke-width {
29+
:where([stroke-width]) {
30+
stroke-width: var(--strokeWidth);
31+
}
32+
}

src/Shared/Components/Icon/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { FC, SVGAttributes, SVGProps } from 'react'
17+
import { FC, SVGProps } from 'react'
1818

1919
import { TooltipProps } from '@Common/Tooltip/types'
2020

2121
type IconMap = Record<string, FC<SVGProps<SVGSVGElement>>>
2222

23-
export interface IconBaseProps extends Pick<SVGAttributes<SVGSVGElement>, 'strokeWidth'> {
23+
export interface IconBaseProps {
2424
/** The name of the icon to render. */
2525
name: keyof IconMap
2626
/** The map containing all available icons. */

0 commit comments

Comments
 (0)