@pushwoosh/kit-helpers 4.9.2 → 4.11.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.
@@ -12,7 +12,7 @@ description: "React component library for building Pushwoosh products with TypeS
12
12
 
13
13
  React component library for building Pushwoosh products with TypeScript, styled-components, and comprehensive hook utilities.
14
14
 
15
- > This page is generated from `ai-documentation.json` and groups the API by Components, Hooks, Utilities, and Types. All styled-component props are prefixed with `$` to avoid DOM prop warnings.
15
+ > This page groups the API by Components, Hooks, Utilities, and Types. All styled-component props are prefixed with `$` to avoid DOM prop warnings.
16
16
 
17
17
  ---
18
18
 
@@ -24,19 +24,39 @@ React component library for building Pushwoosh products with TypeScript, styled-
24
24
  - **Interface:**
25
25
  ```ts
26
26
  GridContainer<{
27
- $alignContent?: 'center' | 'start' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch';
27
+ $alignContent?: 'center' | 'start' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch' | 'baseline';
28
28
  $alignItems?: 'center' | 'start' | 'end' | 'baseline' | 'stretch';
29
+ $basis?: StrNum;
29
30
  $bgColor?: string;
30
31
  $border?: string | CssBoxSides<string>;
31
32
  $borderRadius?: StrNum;
33
+ $bottom?: StrNum;
32
34
  $boxShadow?: string;
35
+ $flex?: StrNum;
33
36
  $gap?: StrNum;
34
37
  $gridAutoFlow?: 'row' | 'column' | 'dense' | 'row dense' | 'column dense';
38
+ $grow?: number;
39
+ $height?: StrNum;
40
+ $inset?: StrNum;
35
41
  $justifyContent?: 'center' | 'start' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch';
36
42
  $justifyItems?: 'center' | 'start' | 'end' | 'baseline' | 'stretch';
43
+ $left?: StrNum;
37
44
  $margin?: StrNum | CssBoxSides<StrNum>;
45
+ $maxHeight?: StrNum;
46
+ $maxWidth?: StrNum;
47
+ $minHeight?: StrNum;
48
+ $minWidth?: StrNum;
49
+ $overflow?: 'hidden' | 'auto' | 'scroll' | 'visible';
50
+ $overflowX?: 'hidden' | 'auto' | 'scroll' | 'visible';
51
+ $overflowY?: 'hidden' | 'auto' | 'scroll' | 'visible';
38
52
  $padding?: StrNum | CssBoxSides<StrNum>;
39
- $placeItems?: 'center' | 'start' | 'end' | 'stretch';
53
+ $placeItems?: 'center' | 'start' | 'end' | 'baseline' | 'stretch';
54
+ $position?: 'static' | 'relative' | 'absolute' | 'fixed' | 'sticky';
55
+ $right?: StrNum;
56
+ $shrink?: number;
57
+ $top?: StrNum;
58
+ $width?: StrNum;
59
+ $zIndex?: number;
40
60
  }>
41
61
  ```
42
62
 
@@ -44,32 +64,71 @@ GridContainer<{
44
64
 
45
65
  | Name | Type | Required | Default | Description | Values |
46
66
  |---|---|:---:|:---:|---|---|
47
- | `$alignContent` | enum | | | Aligns the grid content along the cross axis | `center`, `start`, `end`, `space-between`, `space-around`, `space-evenly`, `stretch` |
67
+ | `$alignContent` | enum | | | Aligns the grid content along the cross axis | `center`, `start`, `end`, `space-between`, `space-around`, `space-evenly`, `stretch`, `baseline` |
48
68
  | `$alignItems` | enum | | | Aligns grid items along the cross axis | `center`, `start`, `end`, `baseline`, `stretch` |
69
+ | `$basis` | string\|number | | | `flex-basis` (only effective when parent is a flex container; number → px) | |
49
70
  | `$bgColor` | string | | | Background color of the grid container | |
50
71
  | `$border` | object | | | Border styling, can be string or object with top/right/bottom/left properties | |
51
72
  | `$borderRadius` | string\|number | | | Border radius, accepts number (converted to px) or string | |
73
+ | `$bottom` | string\|number | | | `bottom` offset (number → px) | |
52
74
  | `$boxShadow` | string | | | CSS box shadow property | |
75
+ | `$flex` | string\|number | | | `flex` shorthand (only effective when parent is a flex container) | |
53
76
  | `$gap` | string\|number | | | Gap between grid items, accepts number (converted to px) or string | |
54
77
  | `$gridAutoFlow` | enum | | | Controls how auto-placed items are inserted in the grid | `row`, `column`, `dense`, `row dense`, `column dense` |
78
+ | `$grow` | number | | | `flex-grow` (only effective when parent is a flex container) | |
79
+ | `$height` | string\|number | | | `height` (number → px; strings like `'100%'` / `'auto'` / `'fit-content'` pass through) | |
80
+ | `$inset` | string\|number | | | `inset` CSS shorthand (number → px, string passes through, e.g. `'10px 20px'`) | |
55
81
  | `$justifyContent` | enum | | | Aligns the grid content along the main axis | `center`, `start`, `end`, `space-between`, `space-around`, `space-evenly`, `stretch` |
56
82
  | `$justifyItems` | enum | | | Aligns grid items along the main axis | `center`, `start`, `end`, `baseline`, `stretch` |
83
+ | `$left` | string\|number | | | `left` offset (number → px) | |
57
84
  | `$margin` | object | | | Margin spacing, can be number/string or object with directional properties | |
85
+ | `$maxHeight` | string\|number | | | `max-height` (number → px) | |
86
+ | `$maxWidth` | string\|number | | | `max-width` (number → px) | |
87
+ | `$minHeight` | string\|number | | | `min-height` (number → px) | |
88
+ | `$minWidth` | string\|number | | | `min-width` (number → px) | |
89
+ | `$overflow` | enum | | | `overflow` | `hidden`, `auto`, `scroll`, `visible` |
90
+ | `$overflowX` | enum | | | `overflow-x` | `hidden`, `auto`, `scroll`, `visible` |
91
+ | `$overflowY` | enum | | | `overflow-y` | `hidden`, `auto`, `scroll`, `visible` |
58
92
  | `$padding` | object | | | Padding spacing, can be number/string or object with directional properties | |
59
- | `$placeItems` | enum | | | Shorthand for align-items and justify-items | `center`, `start`, `end`, `stretch` |
93
+ | `$placeItems` | enum | | | Shorthand for align-items and justify-items | `center`, `start`, `end`, `baseline`, `stretch` |
94
+ | `$position` | enum | | | `position` | `static`, `relative`, `absolute`, `fixed`, `sticky` |
95
+ | `$right` | string\|number | | | `right` offset (number → px) | |
96
+ | `$shrink` | number | | | `flex-shrink` (only effective when parent is a flex container) | |
97
+ | `$top` | string\|number | | | `top` offset (number → px) | |
98
+ | `$width` | string\|number | | | `width` (number → px; strings pass through) | |
99
+ | `$zIndex` | number | | | `z-index` | |
60
100
 
61
- **Example**
101
+ **Examples**
62
102
  ```tsx
63
103
  <GridContainer $gap={16} $padding={20} $bgColor="#f0f0f0">
64
104
  <div>Item 1</div>
65
105
  <div>Item 2</div>
66
106
  </GridContainer>
67
107
  ```
108
+ ```tsx
109
+ // Absolute tooltip
110
+ <GridContainer $position="absolute" $top={40} $left={20} $width={350} $zIndex={10}>
111
+ <Tooltip />
112
+ </GridContainer>
113
+ ```
114
+ ```tsx
115
+ // Stretch horizontally
116
+ <GridContainer $position="absolute" $left={0} $right={0} $bottom={0}>
117
+ <Footer />
118
+ </GridContainer>
119
+ ```
120
+ ```tsx
121
+ // Scrollable region
122
+ <GridContainer $padding={16} $maxHeight={400} $overflow="auto">
123
+ ...
124
+ </GridContainer>
125
+ ```
68
126
 
69
127
  **Notes**
70
128
  - All props are prefixed with `$` to indicate they are styled-component props
71
- - Numbers are automatically converted to `px` units
129
+ - Numbers are automatically converted to `px` units; strings (e.g. `'100%'`, `'fit-content'`, `'2rem'`) pass through unchanged
72
130
  - Use `CssBoxSides` for asymmetric margin/padding/border
131
+ - `$inset` maps directly to the CSS `inset` shorthand; for per-side control use individual `$top` / `$right` / `$bottom` / `$left`
73
132
  - Prefer specific layout components (Columns, Rows, Horizontal, Vertical) for common patterns
74
133
 
75
134
  ---
@@ -179,6 +238,77 @@ GridContainer<{
179
238
 
180
239
  ---
181
240
 
241
+ ### FlexContainer
242
+ - **Path:** `~/src/flex`
243
+ - **Description:** Base flex container component using CSS Flexbox for one-dimensional layouts
244
+ - **Interface:**
245
+ ```ts
246
+ FlexContainer<{
247
+ // Layout (flex-specific)
248
+ $flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse';
249
+ $flexWrap?: 'nowrap' | 'wrap' | 'wrap-reverse';
250
+ // Container alignment (shared with GridContainer)
251
+ $alignContent?: 'center' | 'start' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch' | 'baseline';
252
+ $alignItems?: 'center' | 'start' | 'end' | 'baseline' | 'stretch';
253
+ $gap?: StrNum;
254
+ $justifyContent?: 'center' | 'start' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch';
255
+ // Plus all CommonBoxProps: sizing ($width/$height/$min*/$max*), spacing ($padding/$margin),
256
+ // appearance ($bgColor/$border/$borderRadius/$boxShadow), position ($position/$top/$right/$bottom/$left/$inset/$zIndex),
257
+ // overflow ($overflow/$overflowX/$overflowY), flex-item ($flex/$grow/$shrink/$basis)
258
+ }>
259
+ ```
260
+
261
+ **Props**
262
+
263
+ | Name | Type | Required | Default | Description | Values |
264
+ |---|---|:---:|:---:|---|---|
265
+ | `$flexDirection` | enum | | `row` (browser default) | `flex-direction` — main axis direction | `row`, `row-reverse`, `column`, `column-reverse` |
266
+ | `$flexWrap` | enum | | `nowrap` (browser default) | `flex-wrap` — whether items wrap onto multiple lines | `nowrap`, `wrap`, `wrap-reverse` |
267
+
268
+ Plus everything from `CommonContainerProps` (`$alignContent`, `$alignItems`, `$justifyContent`, `$gap`) and `CommonBoxProps` — see `GridContainer` props table for the full shared list. Grid-specific props (`$gridAutoFlow`, `$justifyItems`, `$placeItems`) are NOT available on `FlexContainer`.
269
+
270
+ **Examples**
271
+ ```tsx
272
+ <FlexContainer $gap={8} $alignItems="center">
273
+ <Icon />
274
+ <span>Label</span>
275
+ </FlexContainer>
276
+ ```
277
+ ```tsx
278
+ // Column with growing child filling remaining space
279
+ <FlexContainer $flexDirection="column" $height="100vh">
280
+ <Header />
281
+ <Main $flex={1} $overflow="auto" />
282
+ <Footer />
283
+ </FlexContainer>
284
+ ```
285
+
286
+ **Notes**
287
+ - Use when items have content-driven sizes or need to wrap; prefer `GridContainer` for explicit 2D tracks
288
+ - Children can use `$flex` / `$grow` / `$shrink` / `$basis` from `CommonBoxProps` to control sizing — this works on any `GridContainer`/`FlexContainer` child too
289
+ - Prefer the `Cluster` preset for wrap-based layouts (tags/chips)
290
+
291
+ ---
292
+
293
+ ### Cluster
294
+ - **Path:** `~/src/flex`
295
+ - **Description:** Flex container with wrapping enabled — for tag/chip/badge groups
296
+ - **Interface:** `Cluster<FlexContainerProps>`
297
+
298
+ **Example**
299
+ ```tsx
300
+ <Cluster $gap={8}>
301
+ {tags.map((tag) => <Tag key={tag.id}>{tag.label}</Tag>)}
302
+ </Cluster>
303
+ ```
304
+
305
+ **Notes**
306
+ - Pre-configured with `$flexWrap: 'wrap'`
307
+ - Inherits all `FlexContainer` props (override `$flexWrap` if needed)
308
+ - Perfect for chip/tag rows that need to wrap on narrow widths
309
+
310
+ ---
311
+
182
312
  ### Collapse
183
313
  - **Path:** `~/src/expand`
184
314
  - **Description:** Animated collapsible component with height transition
@@ -550,7 +680,7 @@ formatNumber(999, 'short') // '999'
550
680
  ---
551
681
 
552
682
  ### toCssValue
553
- - **Path:** `~/src/grid`
683
+ - **Path:** `~/src/styled-helpers` (also re-exported from `~/src/grid` for back-compat)
554
684
  - **Description:** Converts number to px string or returns string as-is
555
685
  - **Signature:** `toCssValue(value: string | number): string`
556
686
 
@@ -561,7 +691,7 @@ toCssValue('2rem') // '2rem'
561
691
  ```
562
692
 
563
693
  **Notes**
564
- - Used internally by grid components
694
+ - Used internally by grid and flex components
565
695
  - Numbers become pixels
566
696
  - Strings pass through unchanged
567
697
  - Enables flexible prop values
@@ -636,6 +766,30 @@ type CssBoxSides<T> =
636
766
  ```
637
767
  - **Description:** Flexible type for directional CSS properties like margin/padding
638
768
 
769
+ ### CommonBoxProps
770
+ - **Path:** `~/src/styled-helpers`
771
+ - **Description:** Shared box-model/positioning/flex-item props consumed by both `GridContainer` and `FlexContainer`. Covers sizing (`$width`, `$height`, `$minWidth`/`$minHeight`, `$maxWidth`/`$maxHeight`), spacing (`$padding`, `$margin`), appearance (`$bgColor`, `$border`, `$borderRadius`, `$boxShadow`), position (`$position`, `$top`/`$right`/`$bottom`/`$left`, `$inset`, `$zIndex`), overflow (`$overflow`/`$overflowX`/`$overflowY`), and flex-item sizing (`$flex`, `$grow`, `$shrink`, `$basis`)
772
+
773
+ ### CommonContainerProps
774
+ - **Path:** `~/src/styled-helpers`
775
+ - **Definition:** `CommonBoxProps & { $alignContent?: AlignContentValue; $alignItems?: ItemAlignmentValue; $gap?: StrNum; $justifyContent?: JustifyContentValue }`
776
+ - **Description:** Extends `CommonBoxProps` with alignment props that work in both grid and flex contexts. Used as the base for `GridContainer` and `FlexContainer` props
777
+
778
+ ### ItemAlignmentValue
779
+ - **Path:** `~/src/styled-helpers`
780
+ - **Definition:** `'center' | 'start' | 'end' | 'baseline' | 'stretch'`
781
+ - **Description:** Valid values for item-level alignment props: `$alignItems`, `$justifyItems`, `$placeItems`
782
+
783
+ ### JustifyContentValue
784
+ - **Path:** `~/src/styled-helpers`
785
+ - **Definition:** `'center' | 'start' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch'`
786
+ - **Description:** Valid values for `$justifyContent`. Per CSS Box Alignment L3, `justify-content` does NOT accept `baseline` — use `AlignContentValue` for `$alignContent`
787
+
788
+ ### AlignContentValue
789
+ - **Path:** `~/src/styled-helpers`
790
+ - **Definition:** `JustifyContentValue | 'baseline'`
791
+ - **Description:** Valid values for `$alignContent`. Same as `JustifyContentValue` plus `baseline` (which is spec-valid only for the cross-axis content distribution)
792
+
639
793
  ### AsyncState
640
794
  - **Definition:** `type AsyncState<T> = { loading: boolean; error?: Error; value?: T }`
641
795
  - **Description:** State shape for async operations with loading, error, and value
@@ -672,6 +826,9 @@ type CssBoxSides<T> =
672
826
 
673
827
  ## Best Practices
674
828
  - Use specific layout components (Columns, Horizontal, Vertical) over generic GridContainer
829
+ - Use the `Cluster` preset for wrap-based layouts; reach for `FlexContainer` for everything else
830
+ - Prefer `FlexContainer` over `GridContainer` when item sizes are content-driven or you need wrapping; prefer Grid when you have explicit row/column tracks
831
+ - Set `$flex` / `$grow` / `$shrink` / `$basis` on any `GridContainer`/`FlexContainer` child to control its size inside a flex parent — no extra wrapper needed
675
832
  - Prefix all styled-component props with `$` to avoid DOM prop warnings
676
833
  - Use `usePersistentFunction` for callbacks passed to memoized components
677
834
  - Check `isMounted()` before state updates in async operations
package/flex.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { CommonContainerProps } from './styled-helpers';
2
+ type FlexContainerProps = CommonContainerProps & {
3
+ $flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse';
4
+ $flexWrap?: 'nowrap' | 'wrap' | 'wrap-reverse';
5
+ };
6
+ export declare const FlexContainer: import("styled-components").StyledComponent<"div", any, FlexContainerProps, never>;
7
+ export declare const Cluster: import("styled-components").StyledComponent<"div", any, import("./styled-helpers").CommonBoxProps & {
8
+ $alignContent?: import("./styled-helpers").AlignContentValue | undefined;
9
+ $alignItems?: import("./styled-helpers").ItemAlignmentValue | undefined;
10
+ $gap?: import("./styled-helpers").StrNum | undefined;
11
+ $justifyContent?: import("./styled-helpers").JustifyContentValue | undefined;
12
+ } & {
13
+ $flexDirection?: "row" | "row-reverse" | "column" | "column-reverse" | undefined;
14
+ $flexWrap?: "wrap" | "nowrap" | "wrap-reverse" | undefined;
15
+ } & {
16
+ $flexWrap: string;
17
+ }, "$flexWrap">;
18
+ export {};
package/flex.js ADDED
@@ -0,0 +1,22 @@
1
+ import styled from 'styled-components';
2
+ import { commonContainerDeclarations, renderDeclarations } from './styled-helpers';
3
+ const flexDeclarations = {
4
+ ...commonContainerDeclarations,
5
+ $flexDirection: {
6
+ property: 'flex-direction'
7
+ },
8
+ $flexWrap: {
9
+ property: 'flex-wrap'
10
+ }
11
+ };
12
+ const renderFlexCss = renderDeclarations(flexDeclarations);
13
+ export const FlexContainer = styled.div.withConfig({
14
+ displayName: "FlexContainer",
15
+ componentId: "sc-vvrarn-0"
16
+ })(["display:flex;", ""], renderFlexCss);
17
+ export const Cluster = styled(FlexContainer).attrs({
18
+ $flexWrap: 'wrap'
19
+ }).withConfig({
20
+ displayName: "Cluster",
21
+ componentId: "sc-vvrarn-1"
22
+ })([""]);
package/grid.d.ts CHANGED
@@ -1,100 +1,56 @@
1
- type StrNum = string | number;
2
- export declare const toCssValue: (value: StrNum) => string;
3
- type CssBoxSides<T> = {
4
- top?: T;
5
- right?: T;
6
- bottom?: T;
7
- left?: T;
8
- } | {
9
- horizontal: T;
10
- top?: T;
11
- bottom?: T;
12
- } | {
13
- vertical: T;
14
- right?: T;
15
- left?: T;
1
+ import { StrNum, ItemAlignmentValue, CommonContainerProps } from './styled-helpers';
2
+ export { toCssValue } from './styled-helpers';
3
+ type GridContainerProps = CommonContainerProps & {
4
+ $gridAutoFlow?: 'row' | 'column' | 'dense' | 'row dense' | 'column dense';
5
+ $justifyItems?: ItemAlignmentValue;
6
+ $placeItems?: ItemAlignmentValue;
16
7
  };
17
- export declare const GridContainer: import("styled-components").StyledComponent<"div", any, {
18
- $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
19
- $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
20
- $bgColor?: string | undefined;
21
- $border?: string | CssBoxSides<string> | undefined;
22
- $borderRadius?: StrNum | undefined;
23
- $boxShadow?: string | undefined;
24
- $gap?: StrNum | undefined;
25
- $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
26
- $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
27
- $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
28
- $margin?: StrNum | CssBoxSides<StrNum> | undefined;
29
- $padding?: StrNum | CssBoxSides<StrNum> | undefined;
30
- $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
31
- }, never>;
32
- export declare const Columns: import("styled-components").StyledComponent<"div", any, {
33
- $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
34
- $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
35
- $bgColor?: string | undefined;
36
- $border?: string | CssBoxSides<string> | undefined;
37
- $borderRadius?: StrNum | undefined;
38
- $boxShadow?: string | undefined;
8
+ export declare const GridContainer: import("styled-components").StyledComponent<"div", any, GridContainerProps, never>;
9
+ export declare const Columns: import("styled-components").StyledComponent<"div", any, import("./styled-helpers").CommonBoxProps & {
10
+ $alignContent?: import("./styled-helpers").AlignContentValue | undefined;
11
+ $alignItems?: ItemAlignmentValue | undefined;
39
12
  $gap?: StrNum | undefined;
13
+ $justifyContent?: import("./styled-helpers").JustifyContentValue | undefined;
14
+ } & {
40
15
  $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
41
- $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
42
- $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
43
- $margin?: StrNum | CssBoxSides<StrNum> | undefined;
44
- $padding?: StrNum | CssBoxSides<StrNum> | undefined;
45
- $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
16
+ $justifyItems?: ItemAlignmentValue | undefined;
17
+ $placeItems?: ItemAlignmentValue | undefined;
46
18
  } & {
47
19
  $sizes: StrNum;
48
20
  }, never>;
49
- export declare const Rows: import("styled-components").StyledComponent<"div", any, {
50
- $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
51
- $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
52
- $bgColor?: string | undefined;
53
- $border?: string | CssBoxSides<string> | undefined;
54
- $borderRadius?: StrNum | undefined;
55
- $boxShadow?: string | undefined;
21
+ export declare const Rows: import("styled-components").StyledComponent<"div", any, import("./styled-helpers").CommonBoxProps & {
22
+ $alignContent?: import("./styled-helpers").AlignContentValue | undefined;
23
+ $alignItems?: ItemAlignmentValue | undefined;
56
24
  $gap?: StrNum | undefined;
25
+ $justifyContent?: import("./styled-helpers").JustifyContentValue | undefined;
26
+ } & {
57
27
  $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
58
- $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
59
- $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
60
- $margin?: StrNum | CssBoxSides<StrNum> | undefined;
61
- $padding?: StrNum | CssBoxSides<StrNum> | undefined;
62
- $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
28
+ $justifyItems?: ItemAlignmentValue | undefined;
29
+ $placeItems?: ItemAlignmentValue | undefined;
63
30
  } & {
64
31
  $sizes: StrNum;
65
32
  }, never>;
66
- export declare const Horizontal: import("styled-components").StyledComponent<"div", any, {
67
- $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
68
- $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
69
- $bgColor?: string | undefined;
70
- $border?: string | CssBoxSides<string> | undefined;
71
- $borderRadius?: StrNum | undefined;
72
- $boxShadow?: string | undefined;
33
+ export declare const Horizontal: import("styled-components").StyledComponent<"div", any, import("./styled-helpers").CommonBoxProps & {
34
+ $alignContent?: import("./styled-helpers").AlignContentValue | undefined;
35
+ $alignItems?: ItemAlignmentValue | undefined;
73
36
  $gap?: StrNum | undefined;
37
+ $justifyContent?: import("./styled-helpers").JustifyContentValue | undefined;
38
+ } & {
74
39
  $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
75
- $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
76
- $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
77
- $margin?: StrNum | CssBoxSides<StrNum> | undefined;
78
- $padding?: StrNum | CssBoxSides<StrNum> | undefined;
79
- $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
40
+ $justifyItems?: ItemAlignmentValue | undefined;
41
+ $placeItems?: ItemAlignmentValue | undefined;
80
42
  } & {
81
43
  $gridAutoFlow: string;
82
44
  }, "$gridAutoFlow">;
83
- export declare const Vertical: import("styled-components").StyledComponent<"div", any, {
84
- $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
85
- $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
86
- $bgColor?: string | undefined;
87
- $border?: string | CssBoxSides<string> | undefined;
88
- $borderRadius?: StrNum | undefined;
89
- $boxShadow?: string | undefined;
45
+ export declare const Vertical: import("styled-components").StyledComponent<"div", any, import("./styled-helpers").CommonBoxProps & {
46
+ $alignContent?: import("./styled-helpers").AlignContentValue | undefined;
47
+ $alignItems?: ItemAlignmentValue | undefined;
90
48
  $gap?: StrNum | undefined;
49
+ $justifyContent?: import("./styled-helpers").JustifyContentValue | undefined;
50
+ } & {
91
51
  $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
92
- $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
93
- $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
94
- $margin?: StrNum | CssBoxSides<StrNum> | undefined;
95
- $padding?: StrNum | CssBoxSides<StrNum> | undefined;
96
- $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
52
+ $justifyItems?: ItemAlignmentValue | undefined;
53
+ $placeItems?: ItemAlignmentValue | undefined;
97
54
  } & {
98
55
  $gridAutoFlow: string;
99
56
  }, "$gridAutoFlow">;
100
- export {};
package/grid.js CHANGED
@@ -1,38 +1,24 @@
1
1
  import styled from 'styled-components';
2
- const isNumber = value => typeof value === 'number';
3
- export const toCssValue = value => isNumber(value) ? `${value}px` : value;
2
+ import { isNumber, commonContainerDeclarations, renderDeclarations } from './styled-helpers';
3
+ export { toCssValue } from './styled-helpers';
4
4
  const gridTemplate = value => isNumber(value) ? `repeat(${value}, 1fr)` : value;
5
- const createCssDeclaration = (property, value, valueConvert) => {
6
- if (value !== undefined) {
7
- return `${property}: ${valueConvert ? valueConvert(value) : value};`;
5
+ const gridDeclarations = {
6
+ ...commonContainerDeclarations,
7
+ $gridAutoFlow: {
8
+ property: 'grid-auto-flow'
9
+ },
10
+ $justifyItems: {
11
+ property: 'justify-items'
12
+ },
13
+ $placeItems: {
14
+ property: 'place-items'
8
15
  }
9
- return undefined;
10
16
  };
11
- function createCssBoxDeclaration(property, value, valueConvert) {
12
- if (typeof value === 'object') {
13
- const declarations = [];
14
- const {
15
- horizontal,
16
- vertical,
17
- ...rest
18
- } = value;
19
- if (horizontal) {
20
- declarations.push(createCssDeclaration(`${property}-left`, horizontal, valueConvert), createCssDeclaration(`${property}-right`, horizontal, valueConvert));
21
- }
22
- if (vertical) {
23
- declarations.push(createCssDeclaration(`${property}-top`, vertical, valueConvert), createCssDeclaration(`${property}-bottom`, vertical, valueConvert));
24
- }
25
- Object.entries(rest).forEach(([key, keyValue]) => {
26
- declarations.push(createCssDeclaration(`${property}-${key}`, keyValue, valueConvert));
27
- });
28
- return declarations.join('');
29
- }
30
- return createCssDeclaration(property, value, valueConvert);
31
- }
17
+ const renderGridCss = renderDeclarations(gridDeclarations);
32
18
  export const GridContainer = styled.div.withConfig({
33
19
  displayName: "GridContainer",
34
20
  componentId: "sc-1mpmh7u-0"
35
- })(["display:grid;", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", ""], props => createCssDeclaration('align-content', props.$alignContent), props => createCssDeclaration('align-items', props.$alignItems), props => createCssDeclaration('background-color', props.$bgColor), props => createCssBoxDeclaration('border', props.$border), props => createCssDeclaration('border-radius', props.$borderRadius, toCssValue), props => createCssDeclaration('box-shadow', props.$boxShadow), props => createCssDeclaration('gap', props.$gap, toCssValue), props => createCssDeclaration('grid-auto-flow', props.$gridAutoFlow), props => createCssDeclaration('justify-content', props.$justifyContent), props => createCssDeclaration('justify-items', props.$justifyItems), props => createCssBoxDeclaration('margin', props.$margin, toCssValue), props => createCssBoxDeclaration('padding', props.$padding, toCssValue), props => createCssDeclaration('place-items', props.$placeItems));
21
+ })(["display:grid;", ""], renderGridCss);
36
22
  export const Columns = styled(GridContainer).withConfig({
37
23
  displayName: "Columns",
38
24
  componentId: "sc-1mpmh7u-1"
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './grid';
2
+ export * from './flex';
2
3
  export * from './expand';
3
4
  export * from './hooks/useClickAway';
4
5
  export { identifyOpenReplaySession } from './analytics/identifyOpenReplay';
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './grid';
2
+ export * from './flex';
2
3
  export * from './expand';
3
4
  export * from './hooks/useClickAway';
4
5
  export { identifyOpenReplaySession } from './analytics/identifyOpenReplay';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/kit-helpers",
3
- "version": "4.9.2",
3
+ "version": "4.11.0",
4
4
  "description": "React component for build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -0,0 +1,66 @@
1
+ export type StrNum = string | number;
2
+ export declare const isNumber: (value: unknown) => value is number;
3
+ export declare const toCssValue: (value: StrNum) => string;
4
+ export declare const createCssDeclaration: (property: string, value: any, valueConvert?: (v: any) => any) => string | undefined;
5
+ export type CssBoxSides<T> = {
6
+ top?: T;
7
+ right?: T;
8
+ bottom?: T;
9
+ left?: T;
10
+ } | {
11
+ horizontal: T;
12
+ top?: T;
13
+ bottom?: T;
14
+ } | {
15
+ vertical: T;
16
+ right?: T;
17
+ left?: T;
18
+ };
19
+ export declare function createCssBoxDeclaration<T>(property: string, value?: StrNum | CssBoxSides<T>, valueConvert?: (v: any) => any): string | undefined;
20
+ export type OverflowValue = 'hidden' | 'auto' | 'scroll' | 'visible';
21
+ export type PositionValue = 'static' | 'relative' | 'absolute' | 'fixed' | 'sticky';
22
+ export type ItemAlignmentValue = 'center' | 'start' | 'end' | 'baseline' | 'stretch';
23
+ export type JustifyContentValue = 'center' | 'start' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch';
24
+ export type AlignContentValue = JustifyContentValue | 'baseline';
25
+ export type CommonBoxProps = {
26
+ $bgColor?: string;
27
+ $basis?: StrNum;
28
+ $border?: string | CssBoxSides<string>;
29
+ $borderRadius?: StrNum;
30
+ $bottom?: StrNum;
31
+ $boxShadow?: string;
32
+ $flex?: StrNum;
33
+ $grow?: number;
34
+ $height?: StrNum;
35
+ $inset?: StrNum;
36
+ $left?: StrNum;
37
+ $margin?: StrNum | CssBoxSides<StrNum>;
38
+ $maxHeight?: StrNum;
39
+ $maxWidth?: StrNum;
40
+ $minHeight?: StrNum;
41
+ $minWidth?: StrNum;
42
+ $overflow?: OverflowValue;
43
+ $overflowX?: OverflowValue;
44
+ $overflowY?: OverflowValue;
45
+ $padding?: StrNum | CssBoxSides<StrNum>;
46
+ $position?: PositionValue;
47
+ $right?: StrNum;
48
+ $shrink?: number;
49
+ $top?: StrNum;
50
+ $width?: StrNum;
51
+ $zIndex?: number;
52
+ };
53
+ export type CommonContainerProps = CommonBoxProps & {
54
+ $alignContent?: AlignContentValue;
55
+ $alignItems?: ItemAlignmentValue;
56
+ $gap?: StrNum;
57
+ $justifyContent?: JustifyContentValue;
58
+ };
59
+ export type CssDeclarationConfig = {
60
+ property: string;
61
+ box?: boolean;
62
+ convert?: (v: any) => any;
63
+ };
64
+ export declare const commonBoxDeclarations: Partial<Record<keyof CommonBoxProps, CssDeclarationConfig>>;
65
+ export declare const commonContainerDeclarations: Partial<Record<keyof CommonContainerProps, CssDeclarationConfig>>;
66
+ export declare const renderDeclarations: <T extends Record<string, any>>(declarations: Partial<Record<keyof T, CssDeclarationConfig>>) => (props: T) => string;
@@ -0,0 +1,151 @@
1
+ export const isNumber = value => typeof value === 'number';
2
+ export const toCssValue = value => isNumber(value) ? `${value}px` : value;
3
+ export const createCssDeclaration = (property, value, valueConvert) => {
4
+ if (value !== undefined) {
5
+ return `${property}: ${valueConvert ? valueConvert(value) : value};`;
6
+ }
7
+ return undefined;
8
+ };
9
+ export function createCssBoxDeclaration(property, value, valueConvert) {
10
+ if (typeof value === 'object') {
11
+ const declarations = [];
12
+ const {
13
+ horizontal,
14
+ vertical,
15
+ ...rest
16
+ } = value;
17
+ if (horizontal) {
18
+ declarations.push(createCssDeclaration(`${property}-left`, horizontal, valueConvert), createCssDeclaration(`${property}-right`, horizontal, valueConvert));
19
+ }
20
+ if (vertical) {
21
+ declarations.push(createCssDeclaration(`${property}-top`, vertical, valueConvert), createCssDeclaration(`${property}-bottom`, vertical, valueConvert));
22
+ }
23
+ Object.entries(rest).forEach(([key, keyValue]) => {
24
+ declarations.push(createCssDeclaration(`${property}-${key}`, keyValue, valueConvert));
25
+ });
26
+ return declarations.join('');
27
+ }
28
+ return createCssDeclaration(property, value, valueConvert);
29
+ }
30
+ export const commonBoxDeclarations = {
31
+ $bgColor: {
32
+ property: 'background-color'
33
+ },
34
+ $basis: {
35
+ property: 'flex-basis',
36
+ convert: toCssValue
37
+ },
38
+ $border: {
39
+ property: 'border',
40
+ box: true
41
+ },
42
+ $borderRadius: {
43
+ property: 'border-radius',
44
+ convert: toCssValue
45
+ },
46
+ $bottom: {
47
+ property: 'bottom',
48
+ convert: toCssValue
49
+ },
50
+ $boxShadow: {
51
+ property: 'box-shadow'
52
+ },
53
+ $flex: {
54
+ property: 'flex'
55
+ },
56
+ $grow: {
57
+ property: 'flex-grow'
58
+ },
59
+ $height: {
60
+ property: 'height',
61
+ convert: toCssValue
62
+ },
63
+ $inset: {
64
+ property: 'inset',
65
+ convert: toCssValue
66
+ },
67
+ $left: {
68
+ property: 'left',
69
+ convert: toCssValue
70
+ },
71
+ $margin: {
72
+ property: 'margin',
73
+ box: true,
74
+ convert: toCssValue
75
+ },
76
+ $maxHeight: {
77
+ property: 'max-height',
78
+ convert: toCssValue
79
+ },
80
+ $maxWidth: {
81
+ property: 'max-width',
82
+ convert: toCssValue
83
+ },
84
+ $minHeight: {
85
+ property: 'min-height',
86
+ convert: toCssValue
87
+ },
88
+ $minWidth: {
89
+ property: 'min-width',
90
+ convert: toCssValue
91
+ },
92
+ $overflow: {
93
+ property: 'overflow'
94
+ },
95
+ $overflowX: {
96
+ property: 'overflow-x'
97
+ },
98
+ $overflowY: {
99
+ property: 'overflow-y'
100
+ },
101
+ $padding: {
102
+ property: 'padding',
103
+ box: true,
104
+ convert: toCssValue
105
+ },
106
+ $position: {
107
+ property: 'position'
108
+ },
109
+ $right: {
110
+ property: 'right',
111
+ convert: toCssValue
112
+ },
113
+ $shrink: {
114
+ property: 'flex-shrink'
115
+ },
116
+ $top: {
117
+ property: 'top',
118
+ convert: toCssValue
119
+ },
120
+ $width: {
121
+ property: 'width',
122
+ convert: toCssValue
123
+ },
124
+ $zIndex: {
125
+ property: 'z-index'
126
+ }
127
+ };
128
+ export const commonContainerDeclarations = {
129
+ ...commonBoxDeclarations,
130
+ $alignContent: {
131
+ property: 'align-content'
132
+ },
133
+ $alignItems: {
134
+ property: 'align-items'
135
+ },
136
+ $gap: {
137
+ property: 'gap',
138
+ convert: toCssValue
139
+ },
140
+ $justifyContent: {
141
+ property: 'justify-content'
142
+ }
143
+ };
144
+ export const renderDeclarations = declarations => props => Object.entries(props).map(([key, value]) => {
145
+ const config = declarations[key];
146
+ if (!config || value === undefined) return undefined;
147
+ if (config.box) {
148
+ return createCssBoxDeclaration(config.property, value, config.convert);
149
+ }
150
+ return createCssDeclaration(config.property, value, config.convert);
151
+ }).filter(Boolean).join('\n');