@dazl/component-gallery 1.0.1 → 2.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.
- package/README.md +4 -2
- package/dist/example/example.d.ts +6 -2
- package/dist/example/example.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/package.json +1 -1
- package/src/example/example.tsx +20 -4
package/README.md
CHANGED
|
@@ -65,13 +65,15 @@ import { Button } from './button';
|
|
|
65
65
|
export default function ButtonExample() {
|
|
66
66
|
return (
|
|
67
67
|
<>
|
|
68
|
-
<Section
|
|
68
|
+
<Section layout="row">
|
|
69
|
+
<Section.Title>Sizes</Section.Title>
|
|
69
70
|
<Button size="sm">Small</Button>
|
|
70
71
|
<Button size="md">Medium</Button>
|
|
71
72
|
<Button size="lg">Large</Button>
|
|
72
73
|
</Section>
|
|
73
74
|
|
|
74
|
-
<Section
|
|
75
|
+
<Section layout="column">
|
|
76
|
+
<Section.Title>States</Section.Title>
|
|
75
77
|
<Button disabled>Disabled</Button>
|
|
76
78
|
<Button loading>Loading</Button>
|
|
77
79
|
</Section>
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export interface SectionProps {
|
|
2
|
-
title?: string;
|
|
3
2
|
layout?: 'row' | 'column';
|
|
4
3
|
children: React.ReactNode;
|
|
5
4
|
}
|
|
6
|
-
export declare const Section:
|
|
5
|
+
export declare const Section: {
|
|
6
|
+
({ layout, children }: SectionProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
Title: import("react").FC<{
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
7
11
|
//# sourceMappingURL=example.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../src/example/example.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../src/example/example.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IACzB,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC7B;AAED,eAAO,MAAM,OAAO;2BAAqC,YAAY;;kBAa5B,KAAK,CAAC,SAAS;;CAFvD,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Children, isValidElement } from "react";
|
|
2
3
|
const section = "section";
|
|
3
4
|
const sectionTitle = "sectionTitle";
|
|
4
5
|
const sectionContentColumn = "sectionContentColumn";
|
|
@@ -9,12 +10,19 @@ const styles = {
|
|
|
9
10
|
sectionContentColumn,
|
|
10
11
|
sectionContentRow
|
|
11
12
|
};
|
|
12
|
-
const Section = ({
|
|
13
|
+
const Section = ({ layout = "column", children }) => {
|
|
14
|
+
const { title, content } = extractTitle(children);
|
|
13
15
|
return /* @__PURE__ */ jsxs("section", { className: styles.section, children: [
|
|
14
|
-
title
|
|
15
|
-
/* @__PURE__ */ jsx("div", { className: layout === "column" ? styles.sectionContentColumn : styles.sectionContentRow, children })
|
|
16
|
+
title,
|
|
17
|
+
/* @__PURE__ */ jsx("div", { className: layout === "column" ? styles.sectionContentColumn : styles.sectionContentRow, children: content })
|
|
16
18
|
] });
|
|
17
19
|
};
|
|
20
|
+
const SectionTitle = ({ children }) => /* @__PURE__ */ jsx("div", { className: styles.sectionTitle, children });
|
|
21
|
+
Section.Title = SectionTitle;
|
|
22
|
+
const extractTitle = (children) => {
|
|
23
|
+
const [title, ...content] = Children.toArray(children);
|
|
24
|
+
return isValidElement(title) && title.type === SectionTitle ? { title, content } : { title: null, content: children };
|
|
25
|
+
};
|
|
18
26
|
export {
|
|
19
27
|
Section
|
|
20
28
|
};
|
package/package.json
CHANGED
package/src/example/example.tsx
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
|
+
import { Children, isValidElement, type ReactNode } from 'react';
|
|
2
|
+
|
|
1
3
|
import styles from './example.module.css';
|
|
2
4
|
|
|
3
5
|
export interface SectionProps {
|
|
4
|
-
title?: string;
|
|
5
6
|
layout?: 'row' | 'column';
|
|
6
7
|
children: React.ReactNode;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const Section = ({
|
|
10
|
+
export const Section = ({ layout = 'column', children }: SectionProps) => {
|
|
11
|
+
const { title, content } = extractTitle(children);
|
|
12
|
+
|
|
10
13
|
return (
|
|
11
14
|
<section className={styles.section}>
|
|
12
|
-
{title
|
|
15
|
+
{title}
|
|
13
16
|
<div className={layout === 'column' ? styles.sectionContentColumn : styles.sectionContentRow}>
|
|
14
|
-
{
|
|
17
|
+
{content}
|
|
15
18
|
</div>
|
|
16
19
|
</section>
|
|
17
20
|
);
|
|
18
21
|
};
|
|
22
|
+
|
|
23
|
+
const SectionTitle: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
24
|
+
<div className={styles.sectionTitle}>{children}</div>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
Section.Title = SectionTitle;
|
|
28
|
+
|
|
29
|
+
const extractTitle = (children: ReactNode): { title: ReactNode; content: ReactNode } => {
|
|
30
|
+
const [title, ...content] = Children.toArray(children);
|
|
31
|
+
return isValidElement(title) && title.type === SectionTitle
|
|
32
|
+
? { title, content }
|
|
33
|
+
: { title: null, content: children };
|
|
34
|
+
};
|