@mbao01/ui 0.0.1 → 0.0.5

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.
@@ -0,0 +1,2 @@
1
+ import { type ButtonProps } from "./types";
2
+ export declare const Button: (props: ButtonProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import type { ButtonSize, ButtonVariant } from './types';
2
+ export declare const getButtonClasses: ({ size, wide, loading, outline, variant, }: {
3
+ size?: ButtonSize | undefined;
4
+ wide?: boolean | undefined;
5
+ loading?: boolean | undefined;
6
+ outline?: boolean | undefined;
7
+ variant?: ButtonVariant | undefined;
8
+ }) => string;
@@ -0,0 +1 @@
1
+ export { Button } from "./Button";
@@ -0,0 +1,12 @@
1
+ import type { ButtonHTMLAttributes, ReactNode } from 'react';
2
+ export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg';
3
+ export type ButtonVariant = 'default' | 'neutral' | 'primary' | 'secondary' | 'accent' | 'ghost' | 'link' | 'info' | 'success' | 'warning' | 'error';
4
+ export type ButtonProps = {
5
+ size?: ButtonSize;
6
+ wide?: boolean;
7
+ label: ReactNode;
8
+ loading?: boolean;
9
+ outline?: boolean;
10
+ variant?: ButtonVariant;
11
+ disabled?: boolean;
12
+ } & ButtonHTMLAttributes<HTMLButtonElement>;
@@ -0,0 +1,4 @@
1
+ import { type TextProps } from './types';
2
+ export declare const Text: ({ as, size, variant, children, className }: TextProps) => import("react").DetailedReactHTMLElement<{
3
+ className: string;
4
+ }, HTMLElement>;
@@ -0,0 +1,5 @@
1
+ import type { TextSize, TextVariant } from './types';
2
+ export declare const getTextClasses: ({ size, variant }: {
3
+ size?: TextSize | undefined;
4
+ variant?: TextVariant | undefined;
5
+ }) => string;
@@ -0,0 +1 @@
1
+ export { Text } from './Text';
@@ -0,0 +1,10 @@
1
+ export type TextSize = 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl';
2
+ export type TextTag = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'p' | 'span';
3
+ export type TextVariant = 'info' | 'error' | 'success' | 'warning' | 'primary' | 'secondary' | 'accent' | 'neutral';
4
+ export type TextProps = {
5
+ as?: TextTag;
6
+ size?: TextSize;
7
+ variant?: TextVariant;
8
+ children: React.ReactNode;
9
+ className?: string;
10
+ };
@@ -1 +1,2 @@
1
1
  export * from "./components/Button";
2
+ export * from "./components/Text";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mbao01/ui",
3
3
  "private": false,
4
- "version": "0.0.1",
4
+ "version": "0.0.5",
5
5
  "type": "module",
6
6
  "author": "Ayomide Bakare",
7
7
  "license": "MIT",
@@ -13,12 +13,12 @@
13
13
  "library"
14
14
  ],
15
15
  "main": "./src/index.ts",
16
- "types": "./dist/index.d.ts",
16
+ "types": "dist/types/index.d.ts",
17
17
  "files": [
18
18
  "src",
19
19
  "plugin.js",
20
20
  "plugin.d.ts",
21
- "dist/index.d.ts"
21
+ "dist/types"
22
22
  ],
23
23
  "sideEffects": false,
24
24
  "scripts": {
@@ -26,7 +26,11 @@
26
26
  "build": "tsc && vite build",
27
27
  "build-storybook": "storybook build",
28
28
  "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
29
- "preview": "vite preview"
29
+ "preview": "vite preview",
30
+ "test": "vitest run",
31
+ "test:ui": "vitest --ui",
32
+ "test:watch": "vitest",
33
+ "test:coverage": "vitest run --coverage"
30
34
  },
31
35
  "dependencies": {
32
36
  "autoprefixer": "^10.4.16",
@@ -43,17 +47,23 @@
43
47
  "@storybook/react": "^7.6.6",
44
48
  "@storybook/react-vite": "^7.6.6",
45
49
  "@storybook/test": "^7.6.6",
50
+ "@testing-library/jest-dom": "^6.1.6",
51
+ "@testing-library/react": "^14.1.2",
52
+ "@testing-library/user-event": "^14.5.2",
46
53
  "@types/node": "^20.10.5",
47
54
  "@types/react": "^18.2.43",
48
55
  "@types/react-dom": "^18.2.17",
49
56
  "@typescript-eslint/eslint-plugin": "^6.14.0",
50
57
  "@typescript-eslint/parser": "^6.14.0",
51
58
  "@vitejs/plugin-react": "^4.2.1",
59
+ "@vitest/coverage-v8": "^1.1.1",
60
+ "@vitest/ui": "^1.1.1",
52
61
  "eslint": "^8.55.0",
53
62
  "eslint-plugin-react": "^7.33.2",
54
63
  "eslint-plugin-react-hooks": "^4.6.0",
55
64
  "eslint-plugin-react-refresh": "^0.4.5",
56
65
  "eslint-plugin-storybook": "^0.6.15",
66
+ "jsdom": "^23.0.1",
57
67
  "path": "^0.12.7",
58
68
  "postcss": "^8.4.32",
59
69
  "react": "^18.2.0",
@@ -62,7 +72,8 @@
62
72
  "tailwindcss": "^3.4.0",
63
73
  "typescript": "^5.2.2",
64
74
  "vite": "^5.0.8",
65
- "vite-plugin-dts": "^3.7.0"
75
+ "vite-plugin-dts": "^3.7.0",
76
+ "vitest": "^1.1.1"
66
77
  },
67
78
  "peerDependencies": {
68
79
  "postcss": "^8.4.32",
@@ -70,5 +81,6 @@
70
81
  "react-dom": "^18.2.0",
71
82
  "tailwindcss": "^3.4.0",
72
83
  "typescript": "^5.2.2"
73
- }
84
+ },
85
+ "gitHead": "c2c9b7d5cfa793a6c9e59f62814aa51de57ee42d"
74
86
  }
@@ -28,7 +28,10 @@ export const Button = (props: ButtonProps) => {
28
28
  >
29
29
  {label}
30
30
  {loading ? (
31
- <span className="absolute left-0 top-0 flex h-full w-full items-center justify-center bg-[inherit]">
31
+ <span
32
+ className="absolute left-0 top-0 flex h-full w-full items-center justify-center bg-[inherit]"
33
+ data-testid="loading"
34
+ >
32
35
  <span className="loading loading-spinner" />
33
36
  </span>
34
37
  ) : null}
@@ -0,0 +1,12 @@
1
+ import c from 'clsx';
2
+ import { createElement } from 'react';
3
+ import { type TextProps } from './types';
4
+ import { getTextClasses } from './constants';
5
+
6
+ export const Text = ({ as = 'span', size, variant, children, className }: TextProps) => {
7
+ return createElement(
8
+ as,
9
+ { className: c(getTextClasses({ size, variant }), className) },
10
+ children
11
+ );
12
+ };
@@ -0,0 +1,29 @@
1
+ import c from 'clsx';
2
+ import type { TextSize, TextVariant } from './types';
3
+
4
+ const TEXT_SIZE = {
5
+ xs: c('text-xs'),
6
+ sm: c('text-sm'),
7
+ base: c('text-base'),
8
+ lg: c('text-lg'),
9
+ xl: c('text-xl'),
10
+ '2xl': c('text-2xl'),
11
+ '3xl': c('text-3xl'),
12
+ '4xl': c('text-4xl'),
13
+ '5xl': c('text-5xl'),
14
+ } satisfies Record<TextSize, string>;
15
+
16
+ const TEXT_VARIANT = {
17
+ info: c('text-info'),
18
+ error: c('text-error'),
19
+ success: c('text-success'),
20
+ warning: c('text-warning'),
21
+ primary: c('text-primary'),
22
+ secondary: c('text-secondary'),
23
+ accent: c('text-accent'),
24
+ neutral: c('text-neutral'),
25
+ } satisfies Record<TextVariant, string>;
26
+
27
+ export const getTextClasses = ({ size, variant }: { size?: TextSize; variant?: TextVariant }) => {
28
+ return c(TEXT_VARIANT[variant!], TEXT_SIZE[size!]);
29
+ };
@@ -0,0 +1 @@
1
+ export { Text } from './Text';
@@ -0,0 +1,21 @@
1
+ export type TextSize = 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl';
2
+
3
+ export type TextTag = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'p' | 'span';
4
+
5
+ export type TextVariant =
6
+ | 'info'
7
+ | 'error'
8
+ | 'success'
9
+ | 'warning'
10
+ | 'primary'
11
+ | 'secondary'
12
+ | 'accent'
13
+ | 'neutral';
14
+
15
+ export type TextProps = {
16
+ as?: TextTag;
17
+ size?: TextSize;
18
+ variant?: TextVariant;
19
+ children: React.ReactNode;
20
+ className?: string;
21
+ };
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./components/Button";
2
+ export * from "./components/Text";
@@ -1,77 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/react';
2
-
3
- import { Button } from './Button';
4
-
5
- // More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
6
- const meta = {
7
- component: Button,
8
- parameters: {
9
- // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/react/configure/story-layout
10
- layout: 'centered',
11
- },
12
- // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
13
- tags: ['autodocs'],
14
- // More on argTypes: https://storybook.js.org/docs/react/api/argtypes
15
- argTypes: {},
16
- } satisfies Meta<typeof Button>;
17
-
18
- export default meta;
19
- type Story = StoryObj<typeof meta>;
20
-
21
- // More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
22
- export const Default: Story = {
23
- args: {
24
- variant: 'default',
25
- label: 'Button',
26
- },
27
- };
28
-
29
- export const PrimaryButton: Story = {
30
- args: {
31
- variant: 'primary',
32
- label: 'Button',
33
- },
34
- };
35
-
36
- export const WideButton: Story = {
37
- args: {
38
- wide: true,
39
- label: 'Wide Button',
40
- },
41
- };
42
-
43
- export const TinyButton: Story = {
44
- args: {
45
- size: 'xs',
46
- label: 'Tiny',
47
- },
48
- };
49
-
50
- export const OutlineButton: Story = {
51
- args: {
52
- outline: true,
53
- label: 'Click me!',
54
- },
55
- };
56
-
57
- export const DisabledButton: Story = {
58
- args: {
59
- disabled: true,
60
- label: 'Click me?',
61
- },
62
- };
63
-
64
- export const LoadingButton: Story = {
65
- args: {
66
- loading: true,
67
- label: 'Loading',
68
- },
69
- };
70
-
71
- export const BlockButton: Story = {
72
- args: {
73
- disabled: true,
74
- className: 'btn-block',
75
- label: 'Block Button',
76
- },
77
- };
package/src/tailwind.css DELETED
@@ -1,25 +0,0 @@
1
- @tailwind base;
2
- @tailwind components;
3
- @tailwind utilities;
4
-
5
- .scroll-shadow {
6
- background-image: linear-gradient(to top, white, white),
7
- linear-gradient(to top, white, white),
8
- linear-gradient(to top, rgba(100, 100, 100, 0.25), rgba(255, 255, 255, 0)),
9
- linear-gradient(to bottom, rgba(100, 100, 100, 0.25), rgba(255, 255, 255, 0));
10
- background-position: bottom center, top center, bottom center, top center;
11
- background-color: white;
12
- background-repeat: no-repeat;
13
- background-size: 100% 12px, 100% 12px, 100% 10px, 100% 10px;
14
- background-attachment: local, local, scroll, scroll;
15
- }
16
-
17
- input[type=number]::-webkit-outer-spin-button,
18
- input[type=number]::-webkit-inner-spin-button {
19
- -webkit-appearance: none;
20
- margin: 0;
21
- }
22
-
23
- input[type=number] {
24
- -moz-appearance: textfield;
25
- }
package/src/vite-env.d.ts DELETED
@@ -1 +0,0 @@
1
- /// <reference types="vite/client" />