@mohammadsalman/storybook-custom-ui 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -2
- package/src/components/Card/Card.tsx +119 -0
- package/src/components/Card/card.stories.tsx +127 -0
- package/src/components/Card/index.ts +1 -0
- package/src/index.ts +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mohammadsalman/storybook-custom-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A minimal React TypeScript component library with Button component and useFormInput hook",
|
|
5
5
|
"main":"src/index.ts",
|
|
6
6
|
"module": "src/index.ts",
|
|
@@ -17,12 +17,15 @@
|
|
|
17
17
|
"button",
|
|
18
18
|
"form-input"
|
|
19
19
|
],
|
|
20
|
-
"author": "
|
|
20
|
+
"author": "Mohammad Salman <mohammadsalman71993@gmail.com>",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
24
|
"url": "https://github.com/MohSalman/creative-ui-react-ui-library.git"
|
|
25
25
|
},
|
|
26
|
+
"runkit": {
|
|
27
|
+
"exampleFilename": "./src/index.ts"
|
|
28
|
+
},
|
|
26
29
|
"peerDependencies": {
|
|
27
30
|
"react": "^18.2.0",
|
|
28
31
|
"react-dom": "^18.2.0"
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useTheme } from '../../theme';
|
|
3
|
+
import { spacing } from '../../utils/styles';
|
|
4
|
+
|
|
5
|
+
export interface CardProps {
|
|
6
|
+
variant?: 'outlined' | 'elevated' | 'flat';
|
|
7
|
+
|
|
8
|
+
heading?: string;
|
|
9
|
+
subheading?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
children?: React.ReactNode;
|
|
12
|
+
className?: string;
|
|
13
|
+
cardContentClass?: string;
|
|
14
|
+
cardHeadingClass?: string;
|
|
15
|
+
cardSubheadingClass?: string;
|
|
16
|
+
cardDescriptionClass?: string;
|
|
17
|
+
cardActionsClass?: string;
|
|
18
|
+
|
|
19
|
+
actions?: React.ReactNode;
|
|
20
|
+
|
|
21
|
+
// Styling
|
|
22
|
+
elevation?: number; // 0-24 (for elevated variant)
|
|
23
|
+
style?: React.CSSProperties;
|
|
24
|
+
|
|
25
|
+
// Optional callbacks
|
|
26
|
+
onClick?: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const Card: React.FC<CardProps> = ({
|
|
30
|
+
variant = 'outlined',
|
|
31
|
+
heading,
|
|
32
|
+
subheading,
|
|
33
|
+
description,
|
|
34
|
+
children,
|
|
35
|
+
className,
|
|
36
|
+
cardContentClass,
|
|
37
|
+
cardHeadingClass,
|
|
38
|
+
cardSubheadingClass,
|
|
39
|
+
cardDescriptionClass,
|
|
40
|
+
cardActionsClass,
|
|
41
|
+
actions,
|
|
42
|
+
elevation = 2, // 0-24 (for elevated variant)
|
|
43
|
+
style,
|
|
44
|
+
onClick,
|
|
45
|
+
...props
|
|
46
|
+
}) => {
|
|
47
|
+
const theme = useTheme();
|
|
48
|
+
|
|
49
|
+
const getVariantStyles = (): React.CSSProperties => {
|
|
50
|
+
switch (variant) {
|
|
51
|
+
case 'outlined':
|
|
52
|
+
return {
|
|
53
|
+
border: `1px solid ${theme.palette.grey[300]}`,
|
|
54
|
+
}
|
|
55
|
+
case 'elevated':
|
|
56
|
+
return {
|
|
57
|
+
boxShadow: theme.shadows[elevation],
|
|
58
|
+
}
|
|
59
|
+
case 'flat':
|
|
60
|
+
return {
|
|
61
|
+
boxShadow: 'none',
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
return {};
|
|
65
|
+
}; }
|
|
66
|
+
|
|
67
|
+
const baseStyles: React.CSSProperties = {
|
|
68
|
+
fontFamily: theme.typography.button.fontFamily,
|
|
69
|
+
lineHeight: theme.typography.button.lineHeight,
|
|
70
|
+
letterSpacing: theme.typography.button.letterSpacing,
|
|
71
|
+
padding: spacing(theme, 2),
|
|
72
|
+
borderRadius: `${theme.shape.borderRadius}px`,
|
|
73
|
+
// cursor: disabled ? 'not-allowed' : 'pointer',
|
|
74
|
+
outline: 'none',
|
|
75
|
+
transition: 'background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
|
|
76
|
+
// width: fullWidth ? '100%' : 'auto',
|
|
77
|
+
// opacity: disabled ? 0.6 : 1,
|
|
78
|
+
...getVariantStyles(),
|
|
79
|
+
// ...getSizeStyles(),
|
|
80
|
+
...style,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const cardContentStyles: React.CSSProperties = {
|
|
84
|
+
fontSize: theme.typography.body1.fontSize,
|
|
85
|
+
fontWeight: theme.typography.body1.fontWeight,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const cardHeadingStyles: React.CSSProperties = {
|
|
89
|
+
fontSize: theme.typography.h6.fontSize,
|
|
90
|
+
fontWeight: theme.typography.h6.fontWeight,
|
|
91
|
+
};
|
|
92
|
+
const cardSubheadingStyles: React.CSSProperties = {
|
|
93
|
+
fontSize: theme.typography.body2.fontSize,
|
|
94
|
+
fontWeight: theme.typography.body2.fontWeight,
|
|
95
|
+
};
|
|
96
|
+
const cardDescriptionStyles: React.CSSProperties = {
|
|
97
|
+
fontSize: theme.typography.body1.fontSize,
|
|
98
|
+
fontWeight: theme.typography.body1.fontWeight,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const cardActionsStyles: React.CSSProperties = {
|
|
102
|
+
display: 'flex',
|
|
103
|
+
justifyContent: 'flex-end',
|
|
104
|
+
alignItems: 'center',
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<div className={className} style={baseStyles} onClick={onClick} {...props}>
|
|
109
|
+
<div className={cardContentClass} style={cardContentStyles}>
|
|
110
|
+
<div className={cardHeadingClass} style={cardHeadingStyles}>{heading}</div>
|
|
111
|
+
<hr/>
|
|
112
|
+
<div className={cardSubheadingClass} style={cardSubheadingStyles}>{subheading}</div>
|
|
113
|
+
<div className={cardDescriptionClass} style={cardDescriptionStyles}>{description}</div>
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
<div className={cardActionsClass} style={cardActionsStyles}>{actions}</div>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Meta, StoryObj } from "@storybook/react"; /* Card Stories */
|
|
2
|
+
import { Card } from "./Card";
|
|
3
|
+
import { Button } from "../Button";
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Card> = {
|
|
6
|
+
title: "Components/Card",
|
|
7
|
+
component: Card,
|
|
8
|
+
tags: ["autodocs"],
|
|
9
|
+
argTypes: {
|
|
10
|
+
variant: {
|
|
11
|
+
control: { type: "select" },
|
|
12
|
+
options: ["outlined", "elevated", "flat"],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
args: {
|
|
16
|
+
variant: "outlined",
|
|
17
|
+
heading: "Card Heading",
|
|
18
|
+
subheading: "Card Subheading",
|
|
19
|
+
description: "Card Description",
|
|
20
|
+
children: "Card Content",
|
|
21
|
+
},
|
|
22
|
+
render: (args) => <Card {...args} />,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default meta;
|
|
26
|
+
type Story = StoryObj<typeof Card>;
|
|
27
|
+
|
|
28
|
+
export const Default: Story = {
|
|
29
|
+
args: {
|
|
30
|
+
variant: "outlined",
|
|
31
|
+
heading: "Card Heading",
|
|
32
|
+
subheading: "Card Subheading",
|
|
33
|
+
description: "Card Description",
|
|
34
|
+
children: "Card Content",
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const Outlined: Story = {
|
|
39
|
+
args: {
|
|
40
|
+
variant: "outlined",
|
|
41
|
+
heading: "Card Heading",
|
|
42
|
+
subheading: "Card Subheading",
|
|
43
|
+
description: "Card Description",
|
|
44
|
+
children: "Card Content",
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const Elevated: Story = {
|
|
49
|
+
args: {
|
|
50
|
+
variant: "elevated",
|
|
51
|
+
heading: "Card Heading",
|
|
52
|
+
subheading: "Card Subheading",
|
|
53
|
+
description: "Card Description",
|
|
54
|
+
children: "Card Content",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const Flat: Story = {
|
|
59
|
+
args: {
|
|
60
|
+
variant: "flat",
|
|
61
|
+
heading: "Card Heading",
|
|
62
|
+
subheading: "Card Subheading",
|
|
63
|
+
description: "Card Description",
|
|
64
|
+
children: "Card Content",
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
export const WithActions: Story = {
|
|
68
|
+
args: {
|
|
69
|
+
variant: "outlined",
|
|
70
|
+
heading: "Card Heading",
|
|
71
|
+
subheading: "Card Subheading",
|
|
72
|
+
description: "Card Description",
|
|
73
|
+
children: "Card Content",
|
|
74
|
+
actions: <Button>Action</Button>,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
export const WithChildren: Story = {
|
|
78
|
+
args: {
|
|
79
|
+
variant: "outlined",
|
|
80
|
+
heading: "Card Heading",
|
|
81
|
+
subheading: "Card Subheading",
|
|
82
|
+
description: "Card Description",
|
|
83
|
+
children: "Card Content",
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
export const WithElevation: Story = {
|
|
87
|
+
args: {
|
|
88
|
+
variant: "elevated",
|
|
89
|
+
heading: "Card Heading",
|
|
90
|
+
subheading: "Card Subheading",
|
|
91
|
+
description: "Card Description",
|
|
92
|
+
children: "Card Content",
|
|
93
|
+
elevation: 2,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
export const WithActionsAndChildren: Story = {
|
|
97
|
+
args: {
|
|
98
|
+
variant: "outlined",
|
|
99
|
+
heading: "Card Heading",
|
|
100
|
+
subheading: "Card Subheading",
|
|
101
|
+
description: "Card Description",
|
|
102
|
+
children: "Card Content",
|
|
103
|
+
actions: <Button>Action</Button>,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
export const WithActionsAndChildrenAndElevation: Story = {
|
|
107
|
+
args: {
|
|
108
|
+
variant: "elevated",
|
|
109
|
+
heading: "Card Heading",
|
|
110
|
+
subheading: "Card Subheading",
|
|
111
|
+
description: "Card Description",
|
|
112
|
+
children: "Card Content",
|
|
113
|
+
actions: <Button>Action</Button>,
|
|
114
|
+
elevation: 2,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
export const WithActionsAndChildrenAndElevationAndVariant: Story = {
|
|
118
|
+
args: {
|
|
119
|
+
variant: "elevated",
|
|
120
|
+
heading: "Card Heading",
|
|
121
|
+
subheading: "Card Subheading",
|
|
122
|
+
description: "Card Description",
|
|
123
|
+
children: "Card Content",
|
|
124
|
+
actions: <Button>Action</Button>,
|
|
125
|
+
elevation: 2,
|
|
126
|
+
},
|
|
127
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Card';
|