@nidhi_kumari/component-library 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 (96) hide show
  1. package/.storybook/main.ts +16 -0
  2. package/.storybook/preview.tsx +21 -0
  3. package/README.md +75 -0
  4. package/eslint.config.js +22 -0
  5. package/index.html +13 -0
  6. package/nidhi_kumari-component-library-1.0.0.tgz +0 -0
  7. package/nidhigupta-component-library-1.0.0.tgz +0 -0
  8. package/package.json +46 -0
  9. package/public/favicon.svg +1 -0
  10. package/public/icons.svg +24 -0
  11. package/src/App.css +184 -0
  12. package/src/App.tsx +122 -0
  13. package/src/assets/hero.png +0 -0
  14. package/src/assets/react.svg +1 -0
  15. package/src/assets/vite.svg +1 -0
  16. package/src/components/Button/Button.css +20 -0
  17. package/src/components/Button/Button.stories.tsx +32 -0
  18. package/src/components/Button/Button.test.tsx +8 -0
  19. package/src/components/Button/Button.tsx +19 -0
  20. package/src/components/Button/Button.types.ts +8 -0
  21. package/src/components/Button/index.ts +2 -0
  22. package/src/components/EmptyState/EmptyState.css +0 -0
  23. package/src/components/EmptyState/EmptyState.stories.tsx +0 -0
  24. package/src/components/EmptyState/EmptyState.tsx +0 -0
  25. package/src/components/EmptyState/EmptyState.types.ts +0 -0
  26. package/src/components/EmptyState/index.ts +0 -0
  27. package/src/components/Header/Header.css +17 -0
  28. package/src/components/Header/Header.stories.tsx +24 -0
  29. package/src/components/Header/Header.tsx +12 -0
  30. package/src/components/Header/Header.types.ts +4 -0
  31. package/src/components/Header/index.ts +2 -0
  32. package/src/components/Input/Input.css +26 -0
  33. package/src/components/Input/Input.stories.tsx +47 -0
  34. package/src/components/Input/Input.tsx +14 -0
  35. package/src/components/Input/Input.types.ts +6 -0
  36. package/src/components/Input/index.ts +2 -0
  37. package/src/components/ListItem/ListItem.css +0 -0
  38. package/src/components/ListItem/ListItem.stories.tsx +0 -0
  39. package/src/components/ListItem/ListItem.tsx +0 -0
  40. package/src/components/ListItem/ListItem.types.ts +0 -0
  41. package/src/components/ListItem/index.ts +0 -0
  42. package/src/components/Loader/Loader.css +0 -0
  43. package/src/components/Loader/Loader.stories.tsx +0 -0
  44. package/src/components/Loader/Loader.tsx +0 -0
  45. package/src/components/Loader/Loader.types.ts +0 -0
  46. package/src/components/Loader/index.ts +0 -0
  47. package/src/components/SearchInput/SearchInput.css +20 -0
  48. package/src/components/SearchInput/SearchInput.stories.tsx +29 -0
  49. package/src/components/SearchInput/SearchInput.tsx +30 -0
  50. package/src/components/SearchInput/SearchInput.types.ts +6 -0
  51. package/src/components/SearchInput/index.ts +2 -0
  52. package/src/components/SearchList/SearchList.css +0 -0
  53. package/src/components/SearchList/SearchList.stories.tsx +0 -0
  54. package/src/components/SearchList/SearchList.tsx +0 -0
  55. package/src/components/SearchList/SearchList.types.ts +0 -0
  56. package/src/components/SearchList/index.ts +0 -0
  57. package/src/components/SlotManagement/SlotManagement.css +223 -0
  58. package/src/components/SlotManagement/SlotManagement.md +0 -0
  59. package/src/components/SlotManagement/SlotManagement.stories.tsx +12 -0
  60. package/src/components/SlotManagement/SlotManagement.tsx +217 -0
  61. package/src/components/SlotManagement/SlotManagement.types.ts +22 -0
  62. package/src/components/SlotManagement/slots.json +40 -0
  63. package/src/index.css +111 -0
  64. package/src/index.ts +0 -0
  65. package/src/main.tsx +10 -0
  66. package/src/stories/Button.stories.ts +54 -0
  67. package/src/stories/Button.tsx +39 -0
  68. package/src/stories/Configure.mdx +388 -0
  69. package/src/stories/Header.stories.ts +34 -0
  70. package/src/stories/Header.tsx +69 -0
  71. package/src/stories/Page.stories.ts +33 -0
  72. package/src/stories/Page.tsx +73 -0
  73. package/src/stories/assets/accessibility.png +0 -0
  74. package/src/stories/assets/accessibility.svg +1 -0
  75. package/src/stories/assets/addon-library.png +0 -0
  76. package/src/stories/assets/assets.png +0 -0
  77. package/src/stories/assets/avif-test-image.avif +0 -0
  78. package/src/stories/assets/context.png +0 -0
  79. package/src/stories/assets/discord.svg +1 -0
  80. package/src/stories/assets/docs.png +0 -0
  81. package/src/stories/assets/figma-plugin.png +0 -0
  82. package/src/stories/assets/github.svg +1 -0
  83. package/src/stories/assets/share.png +0 -0
  84. package/src/stories/assets/styling.png +0 -0
  85. package/src/stories/assets/testing.png +0 -0
  86. package/src/stories/assets/theming.png +0 -0
  87. package/src/stories/assets/tutorials.svg +1 -0
  88. package/src/stories/assets/youtube.svg +1 -0
  89. package/src/stories/button.css +30 -0
  90. package/src/stories/header.css +32 -0
  91. package/src/stories/page.css +68 -0
  92. package/tsconfig.app.json +26 -0
  93. package/tsconfig.json +7 -0
  94. package/tsconfig.node.json +23 -0
  95. package/vite.config.ts +37 -0
  96. package/vitest.shims.d.ts +1 -0
@@ -0,0 +1,217 @@
1
+ import React, { useState } from "react";
2
+ import "./SlotManagement.css";
3
+ import slotsData from "./slots.json";
4
+ import type { SlotWithSelection } from "./SlotManagement.types";
5
+
6
+ const buildInitial = (): SlotWithSelection[] => {
7
+ const raw = slotsData.slots || [];
8
+ return raw.map((s) => ({
9
+ ...s,
10
+ products: (s.products || []).map((p) => ({ ...p, selectedQty: 0 })),
11
+ }));
12
+ };
13
+
14
+ export const SlotManagement: React.FC = () => {
15
+ const [slots, setSlots] = useState<SlotWithSelection[]>(() => buildInitial());
16
+ const [checkedProducts, setCheckedProducts] = useState<Map<string, boolean>>(
17
+ new Map(),
18
+ );
19
+
20
+ const toggleCheck = (slotIndex: number, productIndex: number) => {
21
+ const key = `${slotIndex}-${productIndex}`;
22
+ const newChecked = new Map(checkedProducts);
23
+ newChecked.set(key, !checkedProducts.get(key));
24
+ setCheckedProducts(newChecked);
25
+ };
26
+
27
+ const getSlotSelectedTotal = (slotIndex: number) => {
28
+ return (
29
+ slots[slotIndex]?.products.reduce(
30
+ (sum, product) => sum + product.selectedQty,
31
+ 0,
32
+ ) ?? 0
33
+ );
34
+ };
35
+
36
+ const updateSelected = (
37
+ slotIndex: number,
38
+ productIndex: number,
39
+ next: number,
40
+ ) => {
41
+ setSlots((prev) => {
42
+ const copy = prev.map((s) => ({
43
+ ...s,
44
+ products: s.products.map((p) => ({ ...p })),
45
+ }));
46
+ const slot = copy[slotIndex];
47
+ const currentProduct = slot.products[productIndex];
48
+ const currentTotal = slot.products.reduce(
49
+ (sum, product) => sum + product.selectedQty,
50
+ 0,
51
+ );
52
+ const otherTotal = currentTotal - currentProduct.selectedQty;
53
+ const maxAllowed = slot.maxQty - otherTotal;
54
+ const clampedNext = Math.max(0, Math.min(next, maxAllowed));
55
+
56
+ currentProduct.selectedQty = clampedNext;
57
+ return copy;
58
+ });
59
+ };
60
+
61
+ const increment = (slotIndex: number, productIndex: number) => {
62
+ const current = slots[slotIndex].products[productIndex].selectedQty;
63
+ const currentTotal = getSlotSelectedTotal(slotIndex);
64
+ const slotLimit = slots[slotIndex].maxQty;
65
+
66
+ if (currentTotal >= slotLimit) {
67
+ return;
68
+ }
69
+
70
+ updateSelected(slotIndex, productIndex, current + 1);
71
+ };
72
+
73
+ const decrement = (slotIndex: number, productIndex: number) => {
74
+ const current = slots[slotIndex].products[productIndex].selectedQty;
75
+ updateSelected(slotIndex, productIndex, current - 1);
76
+ };
77
+
78
+ const totalChecked = Array.from(checkedProducts.values()).filter(
79
+ (v) => v,
80
+ ).length;
81
+ const totalProducts = slots.reduce(
82
+ (acc, slot) => acc + slot.products.length,
83
+ 0,
84
+ );
85
+
86
+ const isValidationComplete = slots.every((slot) => {
87
+ const slotTotal = slot.products.reduce(
88
+ (sum, product) => sum + product.selectedQty,
89
+ 0,
90
+ );
91
+
92
+ return slotTotal >= slot.minQty && slotTotal <= slot.maxQty;
93
+ });
94
+
95
+ return (
96
+ <div className="sm-root">
97
+ <div className="sm-header">
98
+ <h2 className="sm-title">Catalog Search</h2>
99
+ </div>
100
+
101
+ <div className="sm-table-wrapper">
102
+ <table className="sm-table">
103
+ <thead>
104
+ <tr>
105
+ <th className="sm-checkbox-col">
106
+ <input type="checkbox" />
107
+ </th>
108
+ <th>Product</th>
109
+ <th>SKU</th>
110
+ <th>Size</th>
111
+ <th>Qty</th>
112
+ <th>Total Price</th>
113
+ <th>Total PR/BV</th>
114
+ </tr>
115
+ </thead>
116
+ <tbody>
117
+ {slots.map((slot, sIdx) => (
118
+ <React.Fragment key={sIdx}>
119
+ <tr className="sm-slot-header-row">
120
+ <td colSpan={7} className="sm-slot-header-cell">
121
+ <div className="sm-slot-header-content">
122
+ <span className="sm-slot-name">{slot.description}</span>
123
+ <span className="sm-slot-constraints">
124
+ Min: {slot.minQty} | Max: {slot.maxQty}
125
+ </span>
126
+ {(() => {
127
+ const slotTotal = getSlotSelectedTotal(sIdx);
128
+ const isFull = slotTotal >= slot.maxQty;
129
+ return (
130
+ <span
131
+ className={`sm-slot-status ${isFull ? "is-full" : ""}`}
132
+ >
133
+ {isFull
134
+ ? "Maximum reached"
135
+ : `${slot.maxQty - slotTotal} remaining`}
136
+ </span>
137
+ );
138
+ })()}
139
+ </div>
140
+ </td>
141
+ </tr>
142
+ {slot.products.map((p, pIdx) => {
143
+ const isChecked =
144
+ checkedProducts.get(`${sIdx}-${pIdx}`) || false;
145
+ const slotTotal = getSlotSelectedTotal(sIdx);
146
+ const isSlotFull = slotTotal >= slot.maxQty;
147
+ return (
148
+ <tr key={`${sIdx}-${pIdx}`} className="sm-row">
149
+ <td className="sm-checkbox-col">
150
+ <input
151
+ type="checkbox"
152
+ checked={isChecked}
153
+ onChange={() => toggleCheck(sIdx, pIdx)}
154
+ />
155
+ </td>
156
+ <td>{p.name}</td>
157
+ <td>{p.sku}</td>
158
+ <td>EA</td>
159
+ <td>
160
+ <div className="sm-stepper">
161
+ <button
162
+ className="sm-stepper-btn"
163
+ onClick={() => decrement(sIdx, pIdx)}
164
+ aria-label={`Decrease ${p.name}`}
165
+ disabled={p.selectedQty <= 0}
166
+ >
167
+
168
+ </button>
169
+ <input
170
+ type="number"
171
+ className="sm-stepper-input"
172
+ value={p.selectedQty}
173
+ onChange={(e) =>
174
+ updateSelected(
175
+ sIdx,
176
+ pIdx,
177
+ parseInt(e.target.value) || 0,
178
+ )
179
+ }
180
+ />
181
+ <button
182
+ className="sm-stepper-btn"
183
+ onClick={() => increment(sIdx, pIdx)}
184
+ aria-label={`Increase ${p.name}`}
185
+ disabled={isSlotFull}
186
+ >
187
+ +
188
+ </button>
189
+ </div>
190
+ </td>
191
+ <td>${(p.price * p.selectedQty).toFixed(2)}</td>
192
+ <td>{(p.price * p.selectedQty * 1.15).toFixed(2)}</td>
193
+ </tr>
194
+ );
195
+ })}
196
+ </React.Fragment>
197
+ ))}
198
+ </tbody>
199
+ </table>
200
+ </div>
201
+
202
+ <div className="sm-selection-info">
203
+ ({totalChecked}/{totalProducts}) Products Selected
204
+ </div>
205
+
206
+ <div className="sm-footer">
207
+ <button className="sm-btn sm-btn-secondary">Back</button>
208
+ <button
209
+ className="sm-btn sm-btn-primary"
210
+ disabled={!isValidationComplete}
211
+ >
212
+ Confirm
213
+ </button>
214
+ </div>
215
+ </div>
216
+ );
217
+ };
@@ -0,0 +1,22 @@
1
+ export type Product = {
2
+ name: string;
3
+ sku: string;
4
+ qty: number; // stock or available qty
5
+ price: number;
6
+ };
7
+
8
+ export type ProductWithSelection = Product & {
9
+ selectedQty: number;
10
+ };
11
+
12
+ export type Slot = {
13
+ maxQty: number;
14
+ minQty: number;
15
+ description: string;
16
+ type: string;
17
+ products: Product[];
18
+ };
19
+
20
+ export type SlotWithSelection = Omit<Slot, "products"> & {
21
+ products: ProductWithSelection[];
22
+ };
@@ -0,0 +1,40 @@
1
+ {
2
+ "slots": [
3
+ {
4
+ "maxQty": 4,
5
+ "minQty": 1,
6
+ "description": "Health and Supplementation",
7
+ "type": "Health",
8
+ "products": [
9
+ {"name": "Plain Digest™ Scrub Buah Esgorot de Fiber Acorn Incredible", "sku": "10N906", "qty": 5, "price": 36.00},
10
+ {"name": "Produkti", "sku": "12087ICO", "qty": 3, "price": 250.00},
11
+ {"name": "Shimmalty Advanced™", "sku": "11708SCO", "qty": 7, "price": 138.50},
12
+ {"name": "Omega 3 Plus 90", "sku": "AB09CO", "qty": 4, "price": 134.70}
13
+ ]
14
+ },
15
+ {
16
+ "maxQty": 10,
17
+ "minQty": 2,
18
+ "description": "Health and Supplementation",
19
+ "type": "Health",
20
+ "products": [
21
+ {"name": "Plain Digest™ Scrub Buah Esgorot de Fiber Acorn Incredible", "sku": "10N906", "qty": 5, "price": 36.00},
22
+ {"name": "Produkti", "sku": "12087ICO", "qty": 3, "price": 250.00},
23
+ {"name": "Shimmalty Advanced™", "sku": "11708SCO", "qty": 7, "price": 138.50},
24
+ {"name": "Omega 3 Plus 90", "sku": "AB09CO", "qty": 4, "price": 134.70}
25
+ ]
26
+ },
27
+ {
28
+ "maxQty": 10,
29
+ "minQty": 2,
30
+ "description": "Health and Supplementation",
31
+ "type": "Health",
32
+ "products": [
33
+ {"name": "Plain Digest™ Scrub Buah Esgorot de Fiber Acorn Incredible", "sku": "10N906", "qty": 5, "price": 36.00},
34
+ {"name": "Produkti", "sku": "12087ICO", "qty": 3, "price": 250.00},
35
+ {"name": "Shimmalty Advanced™", "sku": "11708SCO", "qty": 7, "price": 138.50},
36
+ {"name": "Omega 3 Plus 90", "sku": "AB09CO", "qty": 4, "price": 134.70}
37
+ ]
38
+ }
39
+ ]
40
+ }
package/src/index.css ADDED
@@ -0,0 +1,111 @@
1
+ /* :root {
2
+ --text: #6b6375;
3
+ --text-h: #08060d;
4
+ --bg: #fff;
5
+ --border: #e5e4e7;
6
+ --code-bg: #f4f3ec;
7
+ --accent: #aa3bff;
8
+ --accent-bg: rgba(170, 59, 255, 0.1);
9
+ --accent-border: rgba(170, 59, 255, 0.5);
10
+ --social-bg: rgba(244, 243, 236, 0.5);
11
+ --shadow:
12
+ rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px;
13
+
14
+ --sans: system-ui, 'Segoe UI', Roboto, sans-serif;
15
+ --heading: system-ui, 'Segoe UI', Roboto, sans-serif;
16
+ --mono: ui-monospace, Consolas, monospace;
17
+
18
+ font: 18px/145% var(--sans);
19
+ letter-spacing: 0.18px;
20
+ color-scheme: light dark;
21
+ color: var(--text);
22
+ background: var(--bg);
23
+ font-synthesis: none;
24
+ text-rendering: optimizeLegibility;
25
+ -webkit-font-smoothing: antialiased;
26
+ -moz-osx-font-smoothing: grayscale;
27
+
28
+ @media (max-width: 1024px) {
29
+ font-size: 16px;
30
+ }
31
+ }
32
+
33
+ @media (prefers-color-scheme: dark) {
34
+ :root {
35
+ --text: #9ca3af;
36
+ --text-h: #f3f4f6;
37
+ --bg: #16171d;
38
+ --border: #2e303a;
39
+ --code-bg: #1f2028;
40
+ --accent: #c084fc;
41
+ --accent-bg: rgba(192, 132, 252, 0.15);
42
+ --accent-border: rgba(192, 132, 252, 0.5);
43
+ --social-bg: rgba(47, 48, 58, 0.5);
44
+ --shadow:
45
+ rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px;
46
+ }
47
+
48
+ #social .button-icon {
49
+ filter: invert(1) brightness(2);
50
+ }
51
+ }
52
+
53
+ #root {
54
+ width: 1126px;
55
+ max-width: 100%;
56
+ margin: 0 auto;
57
+ text-align: center;
58
+ border-inline: 1px solid var(--border);
59
+ min-height: 100svh;
60
+ display: flex;
61
+ flex-direction: column;
62
+ box-sizing: border-box;
63
+ }
64
+
65
+ body {
66
+ margin: 0;
67
+ }
68
+
69
+ h1,
70
+ h2 {
71
+ font-family: var(--heading);
72
+ font-weight: 500;
73
+ color: var(--text-h);
74
+ }
75
+
76
+ h1 {
77
+ font-size: 56px;
78
+ letter-spacing: -1.68px;
79
+ margin: 32px 0;
80
+ @media (max-width: 1024px) {
81
+ font-size: 36px;
82
+ margin: 20px 0;
83
+ }
84
+ }
85
+ h2 {
86
+ font-size: 24px;
87
+ line-height: 118%;
88
+ letter-spacing: -0.24px;
89
+ margin: 0 0 8px;
90
+ @media (max-width: 1024px) {
91
+ font-size: 20px;
92
+ }
93
+ }
94
+ p {
95
+ margin: 0;
96
+ }
97
+
98
+ code,
99
+ .counter {
100
+ font-family: var(--mono);
101
+ display: inline-flex;
102
+ border-radius: 4px;
103
+ color: var(--text-h);
104
+ }
105
+
106
+ code {
107
+ font-size: 15px;
108
+ line-height: 135%;
109
+ padding: 4px 8px;
110
+ background: var(--code-bg);
111
+ } */
package/src/index.ts ADDED
File without changes
package/src/main.tsx ADDED
@@ -0,0 +1,10 @@
1
+ import { StrictMode } from 'react'
2
+ import { createRoot } from 'react-dom/client'
3
+ import './index.css'
4
+ import App from './App.tsx'
5
+
6
+ createRoot(document.getElementById('root')!).render(
7
+ <StrictMode>
8
+ <App />
9
+ </StrictMode>,
10
+ )
@@ -0,0 +1,54 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+
3
+ import { fn } from 'storybook/test';
4
+
5
+ import { Button } from './Button';
6
+
7
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
8
+ const meta = {
9
+ title: 'Example/Button',
10
+ component: Button,
11
+ parameters: {
12
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
13
+ layout: 'centered',
14
+ },
15
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
16
+ tags: ['autodocs'],
17
+ // More on argTypes: https://storybook.js.org/docs/api/argtypes
18
+ argTypes: {
19
+ backgroundColor: { control: 'color' },
20
+ },
21
+ // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#story-args
22
+ args: { onClick: fn() },
23
+ } satisfies Meta<typeof Button>;
24
+
25
+ export default meta;
26
+ type Story = StoryObj<typeof meta>;
27
+
28
+ // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
29
+ export const Primary: Story = {
30
+ args: {
31
+ primary: true,
32
+ label: 'Button',
33
+ },
34
+ };
35
+
36
+ export const Secondary: Story = {
37
+ args: {
38
+ label: 'Button',
39
+ },
40
+ };
41
+
42
+ export const Large: Story = {
43
+ args: {
44
+ size: 'large',
45
+ label: 'Button',
46
+ },
47
+ };
48
+
49
+ export const Small: Story = {
50
+ args: {
51
+ size: 'small',
52
+ label: 'Button',
53
+ },
54
+ };
@@ -0,0 +1,39 @@
1
+ import "./button.css";
2
+
3
+ export interface ButtonProps {
4
+ /** Is this the principal call to action on the page? */
5
+ primary?: boolean;
6
+ /** What background color to use */
7
+ backgroundColor?: string;
8
+ /** How large should the button be? */
9
+ size?: "small" | "medium" | "large";
10
+ /** Button contents */
11
+ label: string;
12
+ /** Optional click handler */
13
+ onClick?: () => void;
14
+ }
15
+
16
+ /** Primary UI component for user interaction */
17
+ export const Button = ({
18
+ primary = false,
19
+ size = "medium",
20
+ backgroundColor,
21
+ label,
22
+ ...props
23
+ }: ButtonProps) => {
24
+ const mode = primary
25
+ ? "storybook-button--primary"
26
+ : "storybook-button--secondary";
27
+ return (
28
+ <button
29
+ type="button"
30
+ className={["storybook-button", `storybook-button--${size}`, mode].join(
31
+ " ",
32
+ )}
33
+ style={{ backgroundColor }}
34
+ {...props}
35
+ >
36
+ {label}
37
+ </button>
38
+ );
39
+ };