Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/alert-shape-prop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@cube-dev/ui-kit': patch
---

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.

1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,5 @@ jobs:
exitZeroOnChanges: true
exitOnceUploaded: true
autoAcceptChanges: true
onlyChanged: true
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ jobs:
with:
exitZeroOnChanges: true
exitOnceUploaded: true
onlyChanged: true
debug: true
token: ${{ secrets.GITHUB_TOKEN }}
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
Expand Down
12 changes: 12 additions & 0 deletions src/components/content/Alert/Alert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ CustomStyling.args = {
textAlign: 'center',
fill: '#danger-bg',
};

export const SharpShape = Template.bind({});
SharpShape.args = {
shape: 'sharp',
theme: 'success',
};

export const CardShape = Template.bind({});
CardShape.args = {
shape: 'card',
theme: 'danger',
};
17 changes: 8 additions & 9 deletions src/components/content/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const AlertElement = tasty({
styles: {
display: 'block',
flow: 'column',
radius: '1cr',
radius: {
'': '1cr',
'shape=sharp': '0',
},
padding: '1.5x',
preset: 't3',
color: {
Expand All @@ -31,10 +34,11 @@ const AlertElement = tasty({
border: {
'': '#clear',
...Object.keys(THEMES).reduce((map, type) => {
map[`[data-type="${type}"]`] = THEMES[type].border;
map[`type=${type}`] = THEMES[type].border;

return map;
}, {}),
'shape=sharp': '0',
},
},
});
Expand All @@ -43,14 +47,9 @@ export const Alert = forwardRef(function Alert(
props: CubeAlertProps,
ref: ForwardedRef<HTMLDivElement>,
) {
const { styles, theme, filteredProps } = useAlert(props);
const { styles, mods, filteredProps } = useAlert(props);

return (
<AlertElement
{...filteredProps}
ref={ref}
data-type={theme}
styles={styles}
/>
<AlertElement {...filteredProps} ref={ref} mods={mods} styles={styles} />
);
});
30 changes: 26 additions & 4 deletions src/components/content/Alert/alert.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ describe('<Alert /> component', () => {
useAlert({ theme: 'danger', isDisabled: true }),
);

expect(result.current.theme).toBe('disabled');
expect(result.current.mods.type).toBe('disabled');
});

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

expect(result.current.theme).toBe('danger');
expect(result.current.mods.type).toBe('danger');
});

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

expect(result.current.theme).toBe('danger');
expect(result.current.mods.type).toBe('danger');
});

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

expect(result.current.theme).toBe('danger');
expect(result.current.mods.type).toBe('danger');
});

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

expect(result.current.filteredProps.qa).toBe('test');
});

it('should default to card shape', () => {
const { result } = renderHook(() => useAlert({ theme: 'danger' }));

expect(result.current.mods.shape).toBe('card');
});

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

expect(result.current.mods.shape).toBe('sharp');
});

it('should correctly render card shape', () => {
const { result } = renderHook(() =>
useAlert({ theme: 'success', shape: 'card' }),
);

expect(result.current.mods.shape).toBe('card');
});
});
7 changes: 7 additions & 0 deletions src/components/content/Alert/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ export interface CubeAlertProps
* @default note
*/
theme?: keyof typeof THEMES;
/**
* Shape of the alert's border radius and border.
* - `card` - Card shape with border radius (`1cr`) and border
* - `sharp` - Sharp corners with no border radius or border (`0`)
* @default "card"
*/
shape?: 'card' | 'sharp';
}
8 changes: 6 additions & 2 deletions src/components/content/Alert/use-alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { CubeAlertProps } from './types';
const STYLE_LIST = [...CONTAINER_STYLES, ...TEXT_STYLES] as const;

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

const styles = extractStyles(props, STYLE_LIST);

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

return {
styles,
theme: _theme,
mods: {
shape,
type: _theme,
...mods,
},
filteredProps: filterBaseProps(props, { eventProps: true }),
};
}
Loading