@repobuddy/storybook 2.2.0 → 2.2.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/esm/index.js +31 -18
- package/package.json +1 -1
- package/src/decorators/with_story_card.tsx +30 -29
- package/src/utils/generate_key.ts +14 -0
package/esm/index.js
CHANGED
|
@@ -70,6 +70,19 @@ function showDocSource() {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/utils/generate_key.ts
|
|
75
|
+
/**
|
|
76
|
+
* Generates a key for React collections, falling back to a simple counter-based ID if crypto.randomUUID is unavailable.
|
|
77
|
+
* crypto.randomUUID() requires a secure context (HTTPS, localhost, or 127.0.0.1).
|
|
78
|
+
*
|
|
79
|
+
* This can be moved to `@just-web` in the future.
|
|
80
|
+
*/
|
|
81
|
+
function generateKey(prefix) {
|
|
82
|
+
const randomId = typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
83
|
+
return prefix ? `${prefix}-${randomId}` : randomId;
|
|
84
|
+
}
|
|
85
|
+
|
|
73
86
|
//#endregion
|
|
74
87
|
//#region src/decorators/with_story_card.tsx
|
|
75
88
|
/**
|
|
@@ -159,12 +172,11 @@ function StoryCardContainerWrapper({ Story, ...props }) {
|
|
|
159
172
|
if (context === null) return /* @__PURE__ */ jsx(StoryCardContainer, { children: collector });
|
|
160
173
|
return collector;
|
|
161
174
|
}
|
|
162
|
-
const StoryCardContext = createContext(null);
|
|
163
175
|
function StoryCardContainer({ children }) {
|
|
164
176
|
const [cards, setCards] = useState([]);
|
|
165
177
|
const contextValue = useMemo(() => ({
|
|
166
178
|
addCard(card) {
|
|
167
|
-
const id =
|
|
179
|
+
const id = generateKey("story-card");
|
|
168
180
|
setCards((cards$1) => [...cards$1, {
|
|
169
181
|
...card,
|
|
170
182
|
id
|
|
@@ -189,6 +201,22 @@ function StoryCardContainer({ children }) {
|
|
|
189
201
|
})
|
|
190
202
|
});
|
|
191
203
|
}
|
|
204
|
+
const storyCardTheme = (state, className) => {
|
|
205
|
+
const defaultClassName = storyCardVariants(state);
|
|
206
|
+
if (!className) return defaultClassName;
|
|
207
|
+
return twMerge(defaultClassName, typeof className === "function" ? className({
|
|
208
|
+
...state,
|
|
209
|
+
defaultClassName
|
|
210
|
+
}) : className);
|
|
211
|
+
};
|
|
212
|
+
const storyCardVariants = cva("flex flex-col gap-1 py-3 px-4 rounded text-black dark:text-gray-100", {
|
|
213
|
+
variants: { status: {
|
|
214
|
+
error: "bg-red-100 dark:bg-red-900",
|
|
215
|
+
warn: "bg-yellow-100 dark:bg-yellow-900",
|
|
216
|
+
info: "bg-sky-100 dark:bg-sky-900"
|
|
217
|
+
} },
|
|
218
|
+
defaultVariants: { status: "info" }
|
|
219
|
+
});
|
|
192
220
|
function StoryCardCollector({ Story, title, status, className, content }) {
|
|
193
221
|
const context = useContext(StoryCardContext);
|
|
194
222
|
const cardIdRef = useRef(null);
|
|
@@ -208,22 +236,7 @@ function StoryCardCollector({ Story, title, status, className, content }) {
|
|
|
208
236
|
}, []);
|
|
209
237
|
return /* @__PURE__ */ jsx(Story, {});
|
|
210
238
|
}
|
|
211
|
-
const
|
|
212
|
-
const defaultClassName = storyCardVariants(state);
|
|
213
|
-
if (!className) return defaultClassName;
|
|
214
|
-
return twMerge(defaultClassName, typeof className === "function" ? className({
|
|
215
|
-
...state,
|
|
216
|
-
defaultClassName
|
|
217
|
-
}) : className);
|
|
218
|
-
};
|
|
219
|
-
const storyCardVariants = cva("flex flex-col gap-1 py-3 px-4 rounded text-black dark:text-gray-100", {
|
|
220
|
-
variants: { status: {
|
|
221
|
-
error: "bg-red-100 dark:bg-red-900",
|
|
222
|
-
warn: "bg-yellow-100 dark:bg-yellow-900",
|
|
223
|
-
info: "bg-sky-100 dark:bg-sky-900"
|
|
224
|
-
} },
|
|
225
|
-
defaultVariants: { status: "info" }
|
|
226
|
-
});
|
|
239
|
+
const StoryCardContext = createContext(null);
|
|
227
240
|
|
|
228
241
|
//#endregion
|
|
229
242
|
//#region src/parameters/define_actions_param.ts
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from 'react'
|
|
13
13
|
import type { DecoratorFunction, Renderer } from 'storybook/internal/csf'
|
|
14
14
|
import { twMerge } from 'tailwind-merge'
|
|
15
|
+
import { generateKey } from '../utils/generate_key'
|
|
15
16
|
|
|
16
17
|
export type StoryCardProps = {
|
|
17
18
|
/**
|
|
@@ -144,22 +145,13 @@ function StoryCardContainerWrapper({ Story, ...props }: StoryCardContainerWrappe
|
|
|
144
145
|
return collector
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
interface StoryCardContextValue {
|
|
148
|
-
addCard: (card: StoryCardProps) => string
|
|
149
|
-
removeCard: (id: string) => void
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const StoryCardContext = createContext<StoryCardContextValue | null>(null)
|
|
153
|
-
|
|
154
|
-
type StoryCardWithId = StoryCardProps & { id: string }
|
|
155
|
-
|
|
156
148
|
function StoryCardContainer({ children }: { children: ReactNode }) {
|
|
157
149
|
const [cards, setCards] = useState<StoryCardWithId[]>([])
|
|
158
150
|
|
|
159
151
|
const contextValue: StoryCardContextValue = useMemo(
|
|
160
152
|
() => ({
|
|
161
153
|
addCard(card) {
|
|
162
|
-
const id =
|
|
154
|
+
const id = generateKey('story-card')
|
|
163
155
|
setCards((cards) => [...cards, { ...card, id }])
|
|
164
156
|
return id
|
|
165
157
|
},
|
|
@@ -185,6 +177,30 @@ function StoryCardContainer({ children }: { children: ReactNode }) {
|
|
|
185
177
|
)
|
|
186
178
|
}
|
|
187
179
|
|
|
180
|
+
type StoryCardWithId = StoryCardProps & { id: string }
|
|
181
|
+
|
|
182
|
+
const storyCardTheme = (state: Pick<StoryCardProps, 'status'>, className: StoryCardProps['className']) => {
|
|
183
|
+
const defaultClassName = storyCardVariants(state)
|
|
184
|
+
if (!className) return defaultClassName
|
|
185
|
+
return twMerge(
|
|
186
|
+
defaultClassName,
|
|
187
|
+
typeof className === 'function' ? className({ ...state, defaultClassName }) : className
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const storyCardVariants = cva('flex flex-col gap-1 py-3 px-4 rounded text-black dark:text-gray-100', {
|
|
192
|
+
variants: {
|
|
193
|
+
status: {
|
|
194
|
+
error: 'bg-red-100 dark:bg-red-900',
|
|
195
|
+
warn: 'bg-yellow-100 dark:bg-yellow-900',
|
|
196
|
+
info: 'bg-sky-100 dark:bg-sky-900'
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
defaultVariants: {
|
|
200
|
+
status: 'info'
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
|
|
188
204
|
interface StoryCardCollectorProps extends StoryCardProps {
|
|
189
205
|
Story: ComponentType
|
|
190
206
|
}
|
|
@@ -212,24 +228,9 @@ function StoryCardCollector({ Story, title, status, className, content }: StoryC
|
|
|
212
228
|
return <Story />
|
|
213
229
|
}
|
|
214
230
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return twMerge(
|
|
219
|
-
defaultClassName,
|
|
220
|
-
typeof className === 'function' ? className({ ...state, defaultClassName }) : className
|
|
221
|
-
)
|
|
231
|
+
interface StoryCardContextValue {
|
|
232
|
+
addCard: (card: StoryCardProps) => string
|
|
233
|
+
removeCard: (id: string) => void
|
|
222
234
|
}
|
|
223
235
|
|
|
224
|
-
const
|
|
225
|
-
variants: {
|
|
226
|
-
status: {
|
|
227
|
-
error: 'bg-red-100 dark:bg-red-900',
|
|
228
|
-
warn: 'bg-yellow-100 dark:bg-yellow-900',
|
|
229
|
-
info: 'bg-sky-100 dark:bg-sky-900'
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
defaultVariants: {
|
|
233
|
-
status: 'info'
|
|
234
|
-
}
|
|
235
|
-
})
|
|
236
|
+
const StoryCardContext = createContext<StoryCardContextValue | null>(null)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a key for React collections, falling back to a simple counter-based ID if crypto.randomUUID is unavailable.
|
|
3
|
+
* crypto.randomUUID() requires a secure context (HTTPS, localhost, or 127.0.0.1).
|
|
4
|
+
*
|
|
5
|
+
* This can be moved to `@just-web` in the future.
|
|
6
|
+
*/
|
|
7
|
+
export function generateKey(prefix?: string | undefined): string {
|
|
8
|
+
const randomId =
|
|
9
|
+
typeof crypto !== 'undefined' && crypto.randomUUID
|
|
10
|
+
? crypto.randomUUID()
|
|
11
|
+
: `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`
|
|
12
|
+
|
|
13
|
+
return prefix ? `${prefix}-${randomId}` : randomId
|
|
14
|
+
}
|