Skip to content

Commit 05feada

Browse files
authored
refactor(icons)!: use Box for FlairIcon (#1413)
* refactor(icons)!: use `Box` for `FlairIcon` * fix: format
1 parent 6341b25 commit 05feada

File tree

7 files changed

+38
-90
lines changed

7 files changed

+38
-90
lines changed

.changeset/khaki-ghosts-grow.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@launchpad-ui/icons": minor
3+
---
4+
5+
Use `Box` for `FlairIcon`:
6+
- Round by default
7+
- Prop `gradient` -> `background`

packages/icons/__tests__/Icon.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Icon', () => {
4444

4545
it('renders a flair icon', () => {
4646
render(
47-
<FlairIcon isRounded>
47+
<FlairIcon>
4848
<Icon name="info" size="medium" />
4949
</FlairIcon>,
5050
);

packages/icons/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"test": "vitest run --coverage"
3535
},
3636
"dependencies": {
37+
"@launchpad-ui/box": "workspace:~",
3738
"@launchpad-ui/tokens": "workspace:~",
3839
"class-variance-authority": "0.7.0"
3940
},

packages/icons/src/FlairIcon.tsx

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,21 @@
1-
import type { ComponentProps, ReactElement } from 'react';
2-
import type { IconProps } from './Icon';
1+
import type { BoxProps } from '@launchpad-ui/box';
32

4-
import { cx } from 'class-variance-authority';
5-
import { cloneElement } from 'react';
3+
import { Box } from '@launchpad-ui/box';
64

7-
import styles from './styles/Icon.module.css';
8-
9-
type FlairIconProps = Omit<ComponentProps<'div'>, 'className'> & {
10-
'data-test-id'?: string;
11-
gradient?: 'purpleToBlue' | 'yellowToCyan' | 'pinkToPurple' | 'cyanToBlue' | 'cyanToPurple';
12-
isRounded?: boolean;
13-
children: ReactElement<IconProps>;
14-
};
15-
16-
const FlairIcon = ({
17-
children,
18-
'data-test-id': testId = 'flair-icon',
19-
isRounded,
20-
gradient = 'purpleToBlue',
21-
...props
22-
}: FlairIconProps) => {
23-
const getIconSize = () => {
24-
let iconSize: IconProps['size'] = children.props.size;
25-
26-
if (!iconSize) {
27-
iconSize = 'medium';
28-
}
29-
30-
return iconSize;
31-
};
32-
33-
const icon = cloneElement(children as ReactElement<IconProps>, {
34-
className: styles.flairIcon,
35-
size: getIconSize(),
36-
});
37-
38-
const classes = cx(styles.flairIconContainer, styles[gradient], isRounded && styles.isRounded);
5+
interface FlairIconProps extends BoxProps {}
396

7+
const FlairIcon = ({ children, ...props }: FlairIconProps) => {
408
return (
41-
<div className={classes} {...props} data-test-id={testId}>
42-
{icon}
43-
</div>
9+
<Box
10+
background="$purple-blue"
11+
borderRadius="50%"
12+
color="$white.950"
13+
display="inline-flex"
14+
padding="$400"
15+
{...props}
16+
>
17+
{children}
18+
</Box>
4419
);
4520
};
4621

packages/icons/src/styles/Icon.module.css

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010

1111
.subtle {
12-
fill: var(--lp-color-gray-600);
12+
fill: var(--lp-color-fill-ui-secondary);
1313
}
1414

1515
.small {
@@ -26,41 +26,3 @@
2626
width: var(--lp-size-40);
2727
height: var(--lp-size-40);
2828
}
29-
30-
.flairIcon {
31-
fill: white;
32-
}
33-
34-
.yellowToCyan {
35-
background: var(--lp-color-gradient-yellow-cyan);
36-
}
37-
38-
.cyanToBlue {
39-
background: var(--lp-color-gradient-cyan-blue);
40-
}
41-
42-
.cyanToPurple {
43-
background: var(--lp-color-gradient-cyan-purple);
44-
}
45-
46-
.purpleToBlue {
47-
background: var(--lp-color-gradient-purple-blue);
48-
}
49-
50-
.pinkToPurple {
51-
background: var(--lp-color-gradient-pink-purple);
52-
}
53-
54-
.isRounded {
55-
border-radius: 6.25rem;
56-
}
57-
58-
.flairIconContainer {
59-
display: flex;
60-
flex-direction: row;
61-
justify-content: center;
62-
align-items: center;
63-
padding: var(--lp-spacing-400);
64-
width: fit-content;
65-
height: fit-content;
66-
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
import type { StoryObj } from '@storybook/react';
1+
import type { Meta, StoryObj } from '@storybook/react';
22

33
import { FlairIcon, Icon } from '../src';
44

5-
export default {
5+
const meta: Meta<typeof FlairIcon> = {
66
component: FlairIcon,
77
title: 'Foundations/Icons/FlairIcon',
8-
description:
9-
'Flair icons can be used as either square or circular icons with gradient backgrounds.',
108
parameters: {
119
status: {
1210
type: import.meta.env.STORYBOOK_PACKAGE_STATUS__ICONS,
1311
},
1412
},
1513
};
1614

15+
export default meta;
16+
1717
type Story = StoryObj<typeof FlairIcon>;
1818

19-
export const Circular: Story = {
20-
args: { children: <Icon name="flag" />, isRounded: true },
19+
export const Square: Story = {
20+
args: { children: <Icon name="flag" />, borderRadius: '0' },
2121
};
2222

2323
export const BlueToPurple: Story = {
24-
args: { children: <Icon name="shield-key" />, gradient: 'purpleToBlue' },
24+
args: { children: <Icon name="shield-key" /> },
2525
};
2626

2727
export const YellowToCyan: Story = {
28-
args: { children: <Icon name="arrow-up-right-circle" />, gradient: 'yellowToCyan' },
28+
args: { children: <Icon name="arrow-up-right-circle" />, background: '$yellow-cyan' },
2929
};
3030

3131
export const PinkToPurple: Story = {
32-
args: { children: <Icon name="flask" />, gradient: 'pinkToPurple' },
32+
args: { children: <Icon name="flask" />, background: '$pink-purple' },
3333
};
3434

3535
export const CyanToBlue: Story = {
36-
args: { children: <Icon name="a-to-b" />, gradient: 'cyanToBlue' },
36+
args: { children: <Icon name="a-to-b" />, background: '$cyan-blue' },
3737
};
3838

3939
export const CyanToPurple: Story = {
40-
args: { children: <Icon name="warning" />, gradient: 'cyanToPurple' },
40+
args: { children: <Icon name="warning" />, background: '$cyan-purple' },
4141
};

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)