Skip to content

Commit cec3339

Browse files
authored
feat(Alert): add sharp shape (#877)
1 parent f1bc522 commit cec3339

File tree

10 files changed

+81
-21
lines changed

10 files changed

+81
-21
lines changed

.changeset/alert-shape-prop.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@cube-dev/ui-kit': patch
3+
---
4+
5+
Add `shape` prop to Alert component. The shape prop accepts 'card' (default, 1cr radius with border) or 'sharp' (no border radius or border) values to control border styling.
6+

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@ jobs:
112112
exitZeroOnChanges: true
113113
exitOnceUploaded: true
114114
autoAcceptChanges: true
115+
onlyChanged: true
115116
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}

.github/workflows/pull-request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ jobs:
179179
with:
180180
exitZeroOnChanges: true
181181
exitOnceUploaded: true
182+
onlyChanged: true
182183
debug: true
183184
token: ${{ secrets.GITHUB_TOKEN }}
184185
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"@typescript-eslint/eslint-plugin": "^8.31.0",
137137
"@typescript-eslint/parser": "^8.31.0",
138138
"bytes": "^3.1.2",
139-
"chromatic": "^8.0.0",
139+
"chromatic": "^13.1.4",
140140
"cross-env": "^7.0.3",
141141
"csstype": "^3.1.2",
142142
"dedent": "^0.7.0",

pnpm-lock.yaml

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

src/components/content/Alert/Alert.stories.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,15 @@ CustomStyling.args = {
4848
textAlign: 'center',
4949
fill: '#danger-bg',
5050
};
51+
52+
export const SharpShape = Template.bind({});
53+
SharpShape.args = {
54+
shape: 'sharp',
55+
theme: 'success',
56+
};
57+
58+
export const CardShape = Template.bind({});
59+
CardShape.args = {
60+
shape: 'card',
61+
theme: 'danger',
62+
};

src/components/content/Alert/Alert.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ const AlertElement = tasty({
1313
styles: {
1414
display: 'block',
1515
flow: 'column',
16-
radius: '1cr',
16+
radius: {
17+
'': '1cr',
18+
'shape=sharp': '0',
19+
},
1720
padding: '1.5x',
1821
preset: 't3',
1922
color: {
@@ -31,10 +34,11 @@ const AlertElement = tasty({
3134
border: {
3235
'': '#clear',
3336
...Object.keys(THEMES).reduce((map, type) => {
34-
map[`[data-type="${type}"]`] = THEMES[type].border;
37+
map[`type=${type}`] = THEMES[type].border;
3538

3639
return map;
3740
}, {}),
41+
'shape=sharp': '0',
3842
},
3943
},
4044
});
@@ -43,14 +47,9 @@ export const Alert = forwardRef(function Alert(
4347
props: CubeAlertProps,
4448
ref: ForwardedRef<HTMLDivElement>,
4549
) {
46-
const { styles, theme, filteredProps } = useAlert(props);
50+
const { styles, mods, filteredProps } = useAlert(props);
4751

4852
return (
49-
<AlertElement
50-
{...filteredProps}
51-
ref={ref}
52-
data-type={theme}
53-
styles={styles}
54-
/>
53+
<AlertElement {...filteredProps} ref={ref} mods={mods} styles={styles} />
5554
);
5655
});

src/components/content/Alert/alert.test.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ describe('<Alert /> component', () => {
1717
useAlert({ theme: 'danger', isDisabled: true }),
1818
);
1919

20-
expect(result.current.theme).toBe('disabled');
20+
expect(result.current.mods.type).toBe('disabled');
2121
});
2222

2323
it('should correctly render theme', () => {
2424
const { result } = renderHook(() => useAlert({ theme: 'danger' }));
2525

26-
expect(result.current.theme).toBe('danger');
26+
expect(result.current.mods.type).toBe('danger');
2727
});
2828

2929
it('should correctly render type', () => {
3030
const { result } = renderHook(() => useAlert({ type: 'danger' }));
3131

32-
expect(result.current.theme).toBe('danger');
32+
expect(result.current.mods.type).toBe('danger');
3333
});
3434

3535
it('should correctly render theme', () => {
3636
const { result } = renderHook(() =>
3737
useAlert({ theme: 'danger', type: 'note' }),
3838
);
3939

40-
expect(result.current.theme).toBe('danger');
40+
expect(result.current.mods.type).toBe('danger');
4141
});
4242

4343
it('should add qa', () => {
@@ -47,4 +47,26 @@ describe('<Alert /> component', () => {
4747

4848
expect(result.current.filteredProps.qa).toBe('test');
4949
});
50+
51+
it('should default to card shape', () => {
52+
const { result } = renderHook(() => useAlert({ theme: 'danger' }));
53+
54+
expect(result.current.mods.shape).toBe('card');
55+
});
56+
57+
it('should correctly render sharp shape', () => {
58+
const { result } = renderHook(() =>
59+
useAlert({ theme: 'danger', shape: 'sharp' }),
60+
);
61+
62+
expect(result.current.mods.shape).toBe('sharp');
63+
});
64+
65+
it('should correctly render card shape', () => {
66+
const { result } = renderHook(() =>
67+
useAlert({ theme: 'success', shape: 'card' }),
68+
);
69+
70+
expect(result.current.mods.shape).toBe('card');
71+
});
5072
});

src/components/content/Alert/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,11 @@ export interface CubeAlertProps
1818
* @default note
1919
*/
2020
theme?: keyof typeof THEMES;
21+
/**
22+
* Shape of the alert's border radius and border.
23+
* - `card` - Card shape with border radius (`1cr`) and border
24+
* - `sharp` - Sharp corners with no border radius or border (`0`)
25+
* @default "card"
26+
*/
27+
shape?: 'card' | 'sharp';
2128
}

src/components/content/Alert/use-alert.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CubeAlertProps } from './types';
1111
const STYLE_LIST = [...CONTAINER_STYLES, ...TEXT_STYLES] as const;
1212

1313
export function useAlert(props: CubeAlertProps) {
14-
const { type, isDisabled = false, theme } = props;
14+
const { type, isDisabled = false, theme, shape = 'card', mods } = props;
1515

1616
const styles = extractStyles(props, STYLE_LIST);
1717

@@ -25,7 +25,11 @@ export function useAlert(props: CubeAlertProps) {
2525

2626
return {
2727
styles,
28-
theme: _theme,
28+
mods: {
29+
shape,
30+
type: _theme,
31+
...mods,
32+
},
2933
filteredProps: filterBaseProps(props, { eventProps: true }),
3034
};
3135
}

0 commit comments

Comments
 (0)