Skip to content

Commit 1bae02a

Browse files
authored
Merge pull request #144 from conceptadev/feature/storybook
Feature/storybook
2 parents 5315690 + 7347eca commit 1bae02a

File tree

4 files changed

+141
-4
lines changed

4 files changed

+141
-4
lines changed

stories/AppBar.stories.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ import React from 'react';
33

44
import { AppBar } from '@concepta/react-material-ui';
55
import { Box, MenuItem } from '@mui/material';
6-
import RocketIcon from '@mui/icons-material/RocketOutlined';
76
import PersonIcon from '@mui/icons-material/PersonOutlineOutlined';
87
import HomeIcon from '@mui/icons-material/HomeOutlined';
8+
import rockets from './assets/rockets.svg';
99

1010
const Component = (args) => (
1111
<AppBar.Root {...args}>
1212
<AppBar.Drawer
13-
logo={
14-
<RocketIcon sx={{ color: 'rgba(255,255,255,0.3)', fontSize: 80 }} />
15-
}
13+
logo={rockets}
1614
items={[
1715
{
1816
icon: <HomeIcon />,

stories/AutocompleteField.stories.tsx

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
import { fn } from '@storybook/test';
3+
import { http, HttpResponse } from 'msw';
4+
5+
import { AutocompleteField } from '@concepta/react-material-ui';
6+
7+
const meta = {
8+
component: AutocompleteField,
9+
tags: ['autodocs'],
10+
argTypes: {},
11+
args: {
12+
label: 'Autocomplete Field',
13+
},
14+
parameters: {
15+
msw: {
16+
handlers: [
17+
http.get('/food', ({ request }) => {
18+
const url = new URL(request.url);
19+
const sort = url.searchParams.get('sort');
20+
const sortField = sort?.split(',')[0];
21+
const sortOrder = sort?.split(',')[1];
22+
const filters = url.searchParams.get('filters[]');
23+
const type = filters?.split('||$eq||')[1];
24+
25+
const foodArray = [
26+
{ id: 1, name: 'Carrot', type: 'fruit' },
27+
{ id: 2, name: 'Cesar Salad', type: 'healthy' },
28+
{ id: 3, name: 'Apple', type: 'fruit' },
29+
{ id: 4, name: 'Pizza', type: 'junk' },
30+
{ id: 5, name: 'Banana', type: 'fruit' },
31+
{ id: 6, name: 'Hamburguer', type: 'junk' },
32+
{ id: 7, name: 'Sardines', type: 'healthy' },
33+
];
34+
35+
return HttpResponse.json(
36+
foodArray
37+
.sort((a, b) => {
38+
if (!sortField || !a[sortField] || !b[sortField]) return 0;
39+
40+
if (sortField === 'id') {
41+
return sortOrder === 'ASC' ? a.id - b.id : b.id - a.id;
42+
}
43+
44+
if (sortOrder === 'ASC') {
45+
return a[sortField]?.localeCompare(b[sortField]);
46+
}
47+
48+
if (sortOrder === 'DESC') {
49+
return b[sortField]?.localeCompare(a[sortField]);
50+
}
51+
52+
return 0;
53+
})
54+
.filter((food) => {
55+
return type ? food.type === type : true;
56+
}),
57+
);
58+
}),
59+
],
60+
},
61+
},
62+
} satisfies Meta<typeof AutocompleteField>;
63+
64+
export default meta;
65+
66+
type Story = StoryObj<typeof meta>;
67+
68+
export const Default: Story = {
69+
args: {
70+
options: [
71+
{ value: '1', label: 'Option 1' },
72+
{ value: '2', label: 'Option 2' },
73+
{ value: '3', label: 'Option 3' },
74+
],
75+
label: 'Autocomplete Field',
76+
isLoading: false,
77+
onChange: fn(),
78+
},
79+
};
80+
81+
export const WithOptions: Story = {
82+
args: {
83+
options: [
84+
{ value: '1', label: 'Option 1' },
85+
{ value: '2', label: 'Option 2' },
86+
{ value: '3', label: 'Option 3' },
87+
],
88+
},
89+
};
90+
91+
export const Loading: Story = {
92+
args: {
93+
isLoading: true,
94+
},
95+
};
96+
97+
/**
98+
* If you provide a "resource" prop, the component will fetch the data from the provided path.
99+
*
100+
* The "resourceLabel" and "resourceValue" props are used to define the label and value of the options.
101+
*/
102+
export const ResourceData: Story = {
103+
args: {
104+
label: 'Food',
105+
resource: 'food',
106+
resourceLabel: 'name',
107+
resourceValue: 'id',
108+
},
109+
};
110+
111+
/**
112+
* You can also provide filters and sort options to the resource.
113+
*/
114+
export const ResourceDataWithFilters: Story = {
115+
args: {
116+
label: 'Junk food',
117+
resource: 'food',
118+
resourceLabel: 'name',
119+
resourceValue: 'id',
120+
filters: { 'type||$eq||': 'junk' },
121+
},
122+
};
123+
124+
export const ResourceDataWithSort: Story = {
125+
args: {
126+
label: 'Sorted by name',
127+
resource: 'food',
128+
resourceLabel: 'name',
129+
resourceValue: 'id',
130+
sort: 'name,ASC',
131+
},
132+
};

stories/Avatar.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react';
22
import { fn } from '@storybook/test';
33

44
import { Avatar } from '@concepta/react-material-ui';
5+
import rockets from './assets/rockets.svg';
56

67
const meta = {
78
component: Avatar,
@@ -46,8 +47,13 @@ export const CustomSize: Story = {
4647
},
4748
};
4849

50+
/**
51+
* Background color will only be visible for images with transparency.
52+
*/
53+
4954
export const CustomBackgroundColor: Story = {
5055
args: {
56+
src: rockets,
5157
backgroundColor: '#00bbff',
5258
},
5359
};

stories/assets/rockets.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)