@fabio.caffarello/react-design-system 1.0.0

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.
Files changed (55) hide show
  1. package/README.md +123 -0
  2. package/dist/App.d.ts +3 -0
  3. package/dist/index.cjs +22 -0
  4. package/dist/index.js +439 -0
  5. package/dist/main.d.ts +1 -0
  6. package/dist/setupTests.d.ts +1 -0
  7. package/dist/ui/atoms/BoxWrapper/BoxWrapper.d.ts +4 -0
  8. package/dist/ui/atoms/BoxWrapper/BoxWrapper.stories.d.ts +5 -0
  9. package/dist/ui/atoms/Button/Button.d.ts +6 -0
  10. package/dist/ui/atoms/Button/Button.stories.d.ts +5 -0
  11. package/dist/ui/atoms/Info/Info.d.ts +6 -0
  12. package/dist/ui/atoms/Info/Info.stories.d.ts +5 -0
  13. package/dist/ui/atoms/Input/Input.d.ts +4 -0
  14. package/dist/ui/atoms/Input/Input.stories.d.ts +5 -0
  15. package/dist/ui/atoms/Input/Input.test.d.ts +1 -0
  16. package/dist/ui/atoms/Text/Text.d.ts +11 -0
  17. package/dist/ui/atoms/Text/Text.stories.d.ts +5 -0
  18. package/dist/ui/atoms/Text/Text.test.d.ts +1 -0
  19. package/dist/ui/atoms/index.d.ts +5 -0
  20. package/dist/ui/index.d.ts +3 -0
  21. package/dist/ui/molecules/InputWithLabel/InputWithLabel.d.ts +6 -0
  22. package/dist/ui/molecules/InputWithLabel/InputWithLabel.stories.d.ts +5 -0
  23. package/dist/ui/molecules/index.d.ts +1 -0
  24. package/dist/ui/organisms/LoginBox/LoginBox.d.ts +6 -0
  25. package/dist/ui/organisms/LoginBox/LoginBox.stories.d.ts +5 -0
  26. package/dist/ui/organisms/index.d.ts +1 -0
  27. package/dist/vite.svg +1 -0
  28. package/package.json +71 -0
  29. package/src/App.css +42 -0
  30. package/src/App.tsx +35 -0
  31. package/src/assets/react.svg +1 -0
  32. package/src/index.css +68 -0
  33. package/src/main.tsx +15 -0
  34. package/src/setupTests.ts +1 -0
  35. package/src/style.css +30 -0
  36. package/src/ui/atoms/BoxWrapper/BoxWrapper.stories.tsx +15 -0
  37. package/src/ui/atoms/BoxWrapper/BoxWrapper.tsx +9 -0
  38. package/src/ui/atoms/Button/Button.stories.tsx +16 -0
  39. package/src/ui/atoms/Button/Button.tsx +35 -0
  40. package/src/ui/atoms/Info/Info.stories.tsx +15 -0
  41. package/src/ui/atoms/Info/Info.tsx +35 -0
  42. package/src/ui/atoms/Input/Input.stories.tsx +15 -0
  43. package/src/ui/atoms/Input/Input.test.tsx +54 -0
  44. package/src/ui/atoms/Input/Input.tsx +19 -0
  45. package/src/ui/atoms/Text/Text.stories.tsx +15 -0
  46. package/src/ui/atoms/Text/Text.test.tsx +47 -0
  47. package/src/ui/atoms/Text/Text.tsx +62 -0
  48. package/src/ui/atoms/index.ts +9 -0
  49. package/src/ui/index.ts +3 -0
  50. package/src/ui/molecules/InputWithLabel/InputWithLabel.stories.tsx +17 -0
  51. package/src/ui/molecules/InputWithLabel/InputWithLabel.tsx +21 -0
  52. package/src/ui/molecules/index.ts +1 -0
  53. package/src/ui/organisms/LoginBox/LoginBox.stories.tsx +22 -0
  54. package/src/ui/organisms/LoginBox/LoginBox.tsx +49 -0
  55. package/src/ui/organisms/index.ts +1 -0
@@ -0,0 +1,62 @@
1
+ import type {
2
+ ComponentPropsWithoutRef,
3
+ ElementType,
4
+ HTMLAttributes,
5
+ JSX,
6
+ } from "react";
7
+
8
+ interface Props<T extends ElementType>
9
+ extends HTMLAttributes<JSX.IntrinsicElements> {
10
+ variant?: "heading" | "list" | "paragraph";
11
+ as?: T;
12
+ bold?: boolean;
13
+ italic?: boolean;
14
+ color?: string;
15
+ }
16
+
17
+ type ReturnProps<P extends ElementType> = Props<P> &
18
+ Omit<ComponentPropsWithoutRef<P>, keyof Props<P>>;
19
+
20
+ export default function Text<T extends ElementType = "p">({
21
+ variant,
22
+ bold,
23
+ italic,
24
+ className,
25
+ as,
26
+ color,
27
+ ...rest
28
+ }: ReturnProps<T>) {
29
+ const classNames = [className];
30
+ let Tag: ElementType;
31
+
32
+ if (as) {
33
+ Tag = as;
34
+ } else {
35
+ switch (variant) {
36
+ case "heading":
37
+ Tag = "h2";
38
+ break;
39
+ case "list":
40
+ Tag = "li";
41
+ break;
42
+ case "paragraph":
43
+ default:
44
+ Tag = "p";
45
+ break;
46
+ }
47
+ }
48
+
49
+ if (bold) {
50
+ classNames.push("font-bold");
51
+ }
52
+
53
+ if (italic) {
54
+ classNames.push("italic");
55
+ }
56
+
57
+ if (color) {
58
+ classNames.push(`text-${color}`);
59
+ }
60
+
61
+ return <Tag className={classNames.join(" ")} {...rest} />;
62
+ }
@@ -0,0 +1,9 @@
1
+ export { default as Info } from "./Info/Info";
2
+
3
+ export { default as Text } from "./Text/Text";
4
+
5
+ export { default as Input } from "./Input/Input";
6
+
7
+ export { default as Button } from "./Button/Button";
8
+
9
+ export { default as BoxWrapper } from "./BoxWrapper/BoxWrapper";
@@ -0,0 +1,3 @@
1
+ export * from "./atoms";
2
+ export * from "./molecules";
3
+ export * from "./organisms";
@@ -0,0 +1,17 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import InputWithLabel from "./InputWithLabel";
3
+
4
+ const meta: Meta<typeof InputWithLabel> = {
5
+ title: "UI/Molecules/InputWithLabel",
6
+ component: InputWithLabel,
7
+ };
8
+
9
+ export const Primary: StoryObj<typeof InputWithLabel> = {
10
+ args: {
11
+ label: "Hello from Storybook",
12
+ placeholder: "Type something here",
13
+ id: "storybook-input",
14
+ },
15
+ };
16
+
17
+ export default meta;
@@ -0,0 +1,21 @@
1
+ import type { HTMLProps } from "react";
2
+ import { Text, Input } from "../../atoms";
3
+
4
+ interface Props extends HTMLProps<HTMLInputElement> {
5
+ label: string;
6
+ }
7
+
8
+ export default function InputWithLabel({ label, ...props }: Props) {
9
+ if (!props.id) {
10
+ console.error("InputWithLabel component requires an id prop");
11
+ }
12
+
13
+ return (
14
+ <div className="mb-medium grid gap-small">
15
+ <Text as="label" htmlFor={props.id} className="cursor-pointer">
16
+ {label}
17
+ </Text>
18
+ <Input {...props} />
19
+ </div>
20
+ );
21
+ }
@@ -0,0 +1 @@
1
+ export { default as InputWithLabel } from "./InputWithLabel/InputWithLabel";
@@ -0,0 +1,22 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { fn } from "storybook/test";
3
+ import LoginBox from "./LoginBox";
4
+
5
+ const meta: Meta<typeof LoginBox> = {
6
+ title: "UI/Organisms/LoginBox",
7
+ component: LoginBox,
8
+ parameters: {
9
+ actions: {
10
+ argTypesRegex: "^on.*",
11
+ },
12
+ },
13
+ };
14
+
15
+ export const Primary: StoryObj<typeof LoginBox> = {
16
+ args: {
17
+ className: "w-[300px]",
18
+ onSubmit: fn().mockName("onSubmit"),
19
+ },
20
+ };
21
+
22
+ export default meta;
@@ -0,0 +1,49 @@
1
+ import type { HTMLAttributes } from "react";
2
+ import { Button, BoxWrapper } from "../../atoms";
3
+ import { InputWithLabel } from "../../molecules";
4
+
5
+ interface Props extends HTMLAttributes<HTMLFormElement> {
6
+ onForgotPasswordClick: () => void;
7
+ }
8
+
9
+ export default function LoginBox({
10
+ onForgotPasswordClick,
11
+ className,
12
+ ...props
13
+ }: Props) {
14
+ return (
15
+ <BoxWrapper className={className}>
16
+ <form
17
+ {...props}
18
+ onSubmit={(e) => {
19
+ e.preventDefault();
20
+ if (props.onSubmit) props.onSubmit(e);
21
+ }}
22
+ >
23
+ <InputWithLabel
24
+ id="login-email"
25
+ label="Your email"
26
+ placeholder="myname@email.com"
27
+ />
28
+ <InputWithLabel
29
+ id="login-password"
30
+ label="Your password"
31
+ placeholder="••••••••"
32
+ type="password"
33
+ />
34
+ <div className="flex justify-between">
35
+ <Button
36
+ variant="secondary"
37
+ type="button"
38
+ onClick={onForgotPasswordClick}
39
+ >
40
+ Forgot password?
41
+ </Button>
42
+ <Button variant="regular" type="submit">
43
+ Sign in
44
+ </Button>
45
+ </div>
46
+ </form>
47
+ </BoxWrapper>
48
+ );
49
+ }
@@ -0,0 +1 @@
1
+ export { default as LoginBox } from "./LoginBox/LoginBox";