Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit a2b18ea

Browse files
Merge pull request #128 from Ultimaker/STAR-335-move-components-to-library
STAR-335 move tile styles
2 parents 40eb587 + 02bed1b commit a2b18ea

File tree

12 files changed

+160
-41
lines changed

12 files changed

+160
-41
lines changed

src/components/__tests__/__snapshots__/about_dialog.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ exports[`The AboutDialog component should render 1`] = `
5858
</tbody>
5959
</table>
6060
<FormActions
61-
align="left"
61+
align="right"
6262
>
6363
<Button
6464
appearance="primary"

src/components/__tests__/__snapshots__/form.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports[`The Form component should render 1`] = `
77
onSubmit={[Function]}
88
>
99
<FormActions
10-
align="left"
10+
align="right"
1111
>
1212
<Button
1313
appearance="primary"
@@ -104,10 +104,10 @@ exports[`The Form component should render with a form item 1`] = `
104104
</InputField>
105105
</div>
106106
<FormActions
107-
align="left"
107+
align="right"
108108
>
109109
<div
110-
className="form-actions form-actions--left"
110+
className="form-actions form-actions--right"
111111
>
112112
<div
113113
className="form-actions__btn-container"

src/components/__tests__/__snapshots__/form_actions.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`The form actions component should render its children 1`] = `
44
<div
5-
className="form-actions form-actions--left"
5+
className="form-actions form-actions--right"
66
>
77
<div
88
className="form-actions__btn-container"

src/components/__tests__/__snapshots__/response_error.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ exports[`The ResponseError component should render 1`] = `
77
<Tile
88
alert={true}
99
align="center"
10+
appearance="shadow"
1011
padding="md"
1112
>
1213
<div

src/components/__tests__/__snapshots__/tile.test.tsx.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
exports[`The Tile component should render 1`] = `
44
<div
5-
className="tile padding-md"
5+
className="tile padding-md tile--shadow"
66
style={
77
Object {
8+
"borderRadius": undefined,
89
"textAlign": "left",
910
}
1011
}

src/components/__tests__/tile.test.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,54 @@ describe('The Tile component', () => {
1515
it('should render', () => {
1616
expect(wrapper).toMatchSnapshot();
1717
});
18+
19+
it('should render disabled', () => {
20+
wrapper.setProps({ disabled: true });
21+
expect(wrapper.find('.tile--disabled')).toHaveLength(1);
22+
});
23+
24+
it('should render selected', () => {
25+
wrapper.setProps({ selected: true });
26+
expect(wrapper.find('.tile--selected')).toHaveLength(1);
27+
});
28+
29+
it('should render alert', () => {
30+
wrapper.setProps({ alert: true });
31+
expect(wrapper.find('.tile--alert')).toHaveLength(1);
32+
});
33+
34+
it('should render success', () => {
35+
wrapper.setProps({ success: true });
36+
expect(wrapper.find('.tile--success')).toHaveLength(1);
37+
});
38+
39+
it('should render shadow', () => {
40+
wrapper.setProps({ appearance: 'shadow' });
41+
expect(wrapper.find('.tile--shadow')).toHaveLength(1);
42+
});
43+
44+
it('should render dashed', () => {
45+
wrapper.setProps({ appearance: 'dashed' });
46+
expect(wrapper.find('.tile--dashed')).toHaveLength(1);
47+
});
48+
49+
it('should render flat', () => {
50+
wrapper.setProps({ appearance: 'flat' });
51+
expect(wrapper.find('.tile--flat')).toHaveLength(1);
52+
});
53+
54+
it('should render padding', () => {
55+
wrapper.setProps({ padding: 'lg' });
56+
expect(wrapper.find('.padding-lg')).toHaveLength(1);
57+
});
58+
59+
it('should render radius', () => {
60+
wrapper.setProps({ radius: '0.5rem' });
61+
expect(wrapper.find('.tile').prop('style')).toHaveProperty('borderRadius', '0.5rem');
62+
});
63+
64+
it('should render align', () => {
65+
wrapper.setProps({ align: 'center' });
66+
expect(wrapper.find('.tile').prop('style')).toHaveProperty('textAlign', 'center');
67+
});
1868
});

src/components/form_actions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const FormActions: React.StatelessComponent<FormActionsProps> = ({ align,
2424
};
2525

2626
FormActions.defaultProps = {
27-
align: 'left',
27+
align: 'right',
2828
};
2929

3030
FormActions.displayName = 'FormActions';

src/components/tile.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import classnames from 'classnames';
33

44
export type Padding = 'none' | 'sm' | 'md' | 'lg';
55
export type Align = 'left' | 'center' | 'right';
6+
export type TileAppearance = 'shadow' | 'dashed' | 'flat';
67

78
export interface TileProps {
89
/** The amount of padding to apply: 'none' | 'sm' | 'md' | 'lg' */
@@ -19,17 +20,24 @@ export interface TileProps {
1920
success?: boolean;
2021
/** An optional class name for the tile * */
2122
className?: string;
23+
/** CSS styling: 'shadow' | 'dashed' | 'flat' */
24+
appearance?: TileAppearance;
25+
/** Border radius. Include unit */
26+
radius?: string;
2227
}
2328

2429
export const Tile: React.StatelessComponent<TileProps> = ({
25-
padding, align, children, disabled, selected, alert, success, className,
30+
padding, align, children, disabled, selected, alert, success, className, appearance, radius,
2631
}): JSX.Element => {
27-
const classes = classnames('tile', className, `padding-${padding}`, {
28-
selected, alert, disabled, success,
32+
const classes = classnames('tile', className, `padding-${padding}`, `tile--${appearance}`, {
33+
'tile--selected': selected,
34+
'tile--alert': alert,
35+
'tile--disabled': disabled,
36+
'tile--success': success,
2937
});
3038

3139
return (
32-
<div className={classes} style={{ textAlign: align }}>
40+
<div className={classes} style={{ textAlign: align, borderRadius: radius }}>
3341
<div className="cover" />
3442
{children}
3543
</div>
@@ -39,6 +47,7 @@ export const Tile: React.StatelessComponent<TileProps> = ({
3947
Tile.defaultProps = {
4048
padding: 'md',
4149
align: 'left',
50+
appearance: 'shadow',
4251
};
4352

4453
Tile.displayName = 'Tile';

src/stories/form.stories.tsx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import styles from '@sambego/storybook-styles';
77
import { withInfo } from '@storybook/addon-info';
88
import { withState } from '@dump247/storybook-state';
9+
import { action } from '@storybook/addon-actions';
910

1011
// components
1112
import { ImageFile } from '../components/image_upload';
@@ -25,6 +26,8 @@ import RangeSlider from '../components/range_slider';
2526
import ProfileIcon from '../components/icons/profile_icon';
2627
import Image from '../components/image';
2728
import StaticField from '../components/input_fields/static_field';
29+
import FormActions from '../components/form_actions';
30+
import Button from '../components/button';
2831

2932
const stories = storiesOf('Forms', module);
3033

@@ -371,7 +374,7 @@ stories.add('Upload file field', withState({ value: null })(withInfo('Upload fil
371374
</div>
372375
))));
373376

374-
stories.add('Static input field', withState({ })(withInfo('Static input field')(({ store }) => (
377+
stories.add('Static input field', withState({})(withInfo('Static input field')(({ store }) => (
375378
<div style={{ width: 350 }}>
376379
<StaticField
377380
id="id_12"
@@ -387,3 +390,33 @@ stories.add('Static input field', withState({ })(withInfo('Static input field')(
387390
</StaticField>
388391
</div>
389392
))));
393+
394+
const alignOptions = {
395+
left: 'left',
396+
right: 'right',
397+
center: 'center',
398+
};
399+
const alignDefaultValue = 'right';
400+
401+
stories.add('Form actions', withInfo(
402+
'Action button container for forms',
403+
)(() => (
404+
<div style={{ minWidth: '500px' }}>
405+
<Tile>
406+
<FormActions align={selectV2('Align', alignOptions, alignDefaultValue)}>
407+
<Button
408+
onClickHandler={action('clicked')}
409+
appearance="primary"
410+
>
411+
{text('Text 1', 'Submit')}
412+
</Button>
413+
<Button
414+
onClickHandler={action('clicked')}
415+
appearance="quiet"
416+
>
417+
{text('Text 2', 'Cancel')}
418+
</Button>
419+
</FormActions>
420+
</Tile>
421+
</div>
422+
)));

src/stories/layout.stories.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ const breakpointOptions = {
6666
};
6767
const breakpointDefaultValue = 'sm';
6868

69+
const tileAppearanceOptions = {
70+
shadow: 'shadow',
71+
dashed: 'dashed',
72+
flat: 'flat',
73+
};
74+
const tileAppearanceDefaultValue = 'shadow';
75+
6976
stories.add('Tile', withInfo(
7077
'A content tile that can be used as full width or as part of a grid',
7178
)(() => (
@@ -76,6 +83,8 @@ stories.add('Tile', withInfo(
7683
success={boolean('Success', false)}
7784
padding={selectV2('Padding', spacingOptions, spacingDefaultValue)}
7885
align={selectV2('Align', alignOptions, alignDefaultValue)}
86+
appearance={selectV2('Appearance', tileAppearanceOptions, tileAppearanceDefaultValue)}
87+
radius={text('Radius', '')}
7988
>
8089
<div>Tile</div>
8190
<div style={{ marginTop: '1.2rem' }}>Component</div>

0 commit comments

Comments
 (0)