|
1 | 1 | import { concatenateResources } from "../util/resources" |
| 2 | +import DesktopOnly from './DesktopOnly' |
2 | 3 | import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" |
3 | 4 |
|
4 | 5 | type FlexConfig = { |
5 | | - components: { |
6 | | - Component: QuartzComponent |
7 | | - grow?: boolean |
8 | | - shrink?: boolean |
9 | | - basis?: string |
10 | | - order?: number |
11 | | - align?: "start" | "end" | "center" | "stretch" |
12 | | - justify?: "start" | "end" | "center" | "between" | "around" |
13 | | - }[] |
14 | | - direction?: "row" | "row-reverse" | "column" | "column-reverse" |
15 | | - wrap?: "nowrap" | "wrap" | "wrap-reverse" |
16 | | - gap?: string |
| 6 | + components: { |
| 7 | + Component: QuartzComponent |
| 8 | + grow?: boolean |
| 9 | + shrink?: boolean |
| 10 | + basis?: string |
| 11 | + order?: number |
| 12 | + align?: "start" | "end" | "center" | "stretch" |
| 13 | + justify?: "start" | "end" | "center" | "between" | "around" |
| 14 | + desktopOnly?: boolean |
| 15 | + }[] |
| 16 | + direction?: "row" | "row-reverse" | "column" | "column-reverse" |
| 17 | + wrap?: "nowrap" | "wrap" | "wrap-reverse" |
| 18 | + gap?: string |
17 | 19 | } |
18 | 20 |
|
19 | 21 | export default ((config: FlexConfig) => { |
20 | | - const Flex: QuartzComponent = (props: QuartzComponentProps) => { |
21 | | - const direction = config.direction ?? "row" |
22 | | - const wrap = config.wrap ?? "nowrap" |
23 | | - const gap = config.gap ?? "1rem" |
| 22 | + const Flex: QuartzComponent = (props: QuartzComponentProps) => { |
| 23 | + const direction = config.direction ?? "row" |
| 24 | + const wrap = config.wrap ?? "nowrap" |
| 25 | + const gap = config.gap ?? "1rem" |
24 | 26 |
|
25 | | - return ( |
26 | | - <div style={`display: flex; flex-direction: ${direction}; flex-wrap: ${wrap}; gap: ${gap};`}> |
27 | | - {config.components.map((c) => { |
28 | | - const grow = c.grow ? 1 : 0 |
29 | | - const shrink = (c.shrink ?? true) ? 1 : 0 |
30 | | - const basis = c.basis ?? "auto" |
31 | | - const order = c.order ?? 0 |
32 | | - const align = c.align ?? "center" |
33 | | - const justify = c.justify ?? "center" |
34 | | - |
35 | | - return ( |
| 27 | + return ( |
36 | 28 | <div |
37 | | - style={`flex-grow: ${grow}; flex-shrink: ${shrink}; flex-basis: ${basis}; order: ${order}; align-self: ${align}; justify-self: ${justify};`} |
| 29 | + class="flex-container" |
| 30 | + // style={`display: flex; flex-direction: ${direction}; gap: ${gap};`} |
38 | 31 | > |
39 | | - <c.Component {...props} /> |
| 32 | + {config.components.map((c, i) => { |
| 33 | + const grow = c.grow ? 1 : 0 |
| 34 | + const shrink = (c.shrink ?? true) ? 1 : 0 |
| 35 | + const basis = c.basis ?? "auto" |
| 36 | + const order = c.order ?? 0 |
| 37 | + const align = c.align ?? "center" |
| 38 | + const justify = c.justify ?? "end" |
| 39 | + const desktopOnly = c.desktopOnly ?? false |
| 40 | + |
| 41 | + return ( |
| 42 | + <div |
| 43 | + class={`flex-child ${i === 0 ? "first-child" : "other-child"} ${desktopOnly ? "flex-desktop-only" : ""}`} |
| 44 | + // style={`flex-grow: ${grow}; flex-shrink: ${shrink}; order: ${order}; align-self: ${align}; justify-self: ${justify};`} |
| 45 | + > |
| 46 | + <c.Component {...props} /> |
| 47 | + </div> |
| 48 | + ) |
| 49 | + })} |
40 | 50 | </div> |
41 | | - ) |
42 | | - })} |
43 | | - </div> |
44 | | - ) |
45 | | - } |
| 51 | + ) |
| 52 | + } |
46 | 53 |
|
47 | | - Flex.afterDOMLoaded = concatenateResources( |
48 | | - ...config.components.map((c) => c.Component.afterDOMLoaded), |
49 | | - ) |
50 | | - Flex.beforeDOMLoaded = concatenateResources( |
51 | | - ...config.components.map((c) => c.Component.beforeDOMLoaded), |
52 | | - ) |
53 | | - Flex.css = concatenateResources(...config.components.map((c) => c.Component.css)) |
54 | | - return Flex |
| 54 | + Flex.afterDOMLoaded = concatenateResources( |
| 55 | + ...config.components.map((c) => c.Component.afterDOMLoaded), |
| 56 | + ) |
| 57 | + Flex.beforeDOMLoaded = concatenateResources( |
| 58 | + ...config.components.map((c) => c.Component.beforeDOMLoaded), |
| 59 | + ) |
| 60 | + Flex.css = concatenateResources(...config.components.map((c) => c.Component.css)) |
| 61 | + return Flex |
55 | 62 | }) satisfies QuartzComponentConstructor<FlexConfig> |
0 commit comments