@linzjs/lui 21.25.0 → 21.26.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [21.26.0](https://github.com/linz/lui/compare/v21.25.0...v21.26.0) (2024-04-11)
2
+
3
+
4
+ ### Features
5
+
6
+ * **Splitter:** add boundaries as px ([#1107](https://github.com/linz/lui/issues/1107)) ([6551d5a](https://github.com/linz/lui/commit/6551d5ade05966d514a9e1202d3f7c4fcb325d4d))
7
+
1
8
  # [21.25.0](https://github.com/linz/lui/compare/v21.24.4...v21.25.0) (2024-04-11)
2
9
 
3
10
 
@@ -6,5 +6,8 @@ export declare const Separator: React.ForwardRefExoticComponent<Pick<React.Detai
6
6
  parts?: Parts;
7
7
  ratio?: number | undefined;
8
8
  onResized?: ((val: number) => void) | undefined;
9
+ min?: number | `${number}px` | undefined;
10
+ max?: number | `${number}px` | undefined;
11
+ startAt?: number | undefined;
9
12
  } & React.RefAttributes<HTMLDivElement>>;
10
13
  export {};
@@ -1,30 +1,44 @@
1
1
  import React, { ComponentPropsWithRef } from 'react';
2
+ import { HTMLAttributes } from 'react';
2
3
  import './Splitter.scss';
3
4
  import { LuiButton } from '../LuiButton/LuiButton';
4
5
  declare type ButtonProps = Omit<ComponentPropsWithRef<typeof LuiButton>, 'children'> & {
5
6
  children?: React.ReactNode;
6
7
  };
8
+ declare type BoundaryPx = {
9
+ min?: `${number}px`;
10
+ max?: `${number}px`;
11
+ };
12
+ declare type BoundaryNum = {
13
+ min?: number;
14
+ max?: number;
15
+ };
16
+ declare type BoundaryProps = BoundaryPx | BoundaryNum;
17
+ declare type Start = number | '1st-collapsed' | '2nd-collapsed';
18
+ declare type Controlled = {
19
+ ratio?: number;
20
+ startAt?: never;
21
+ };
22
+ declare type Uncontrolled = {
23
+ ratio?: never;
24
+ startAt?: Start;
25
+ };
26
+ declare type RatioProps = Controlled | Uncontrolled;
27
+ declare type Props = {
28
+ onResized?: (ratio: number) => void;
29
+ orientation?: 'horizontal' | 'vertical';
30
+ parts?: {
31
+ separator?: ComponentPropsWithRef<'div'>;
32
+ controls?: {
33
+ container?: ComponentPropsWithRef<'span'>;
34
+ primary?: ButtonProps;
35
+ secondary?: ButtonProps;
36
+ };
37
+ };
38
+ } & HTMLAttributes<HTMLDivElement> & RatioProps & BoundaryProps;
7
39
  /**
8
40
  * Container that appends a separator when the children count equals 2.
9
41
  * It looks at HTML nodes, not React components
10
42
  */
11
- export declare const Splitter: React.ForwardRefExoticComponent<{
12
- ratio?: number | undefined;
13
- min?: number | undefined;
14
- max?: number | undefined;
15
- onResized?: ((ratio: number) => void) | undefined;
16
- orientation?: "horizontal" | "vertical" | undefined;
17
- parts?: {
18
- separator?: (Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
19
- ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
20
- }) | undefined;
21
- controls?: {
22
- container?: (Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & {
23
- ref?: ((instance: HTMLSpanElement | null) => void) | React.RefObject<HTMLSpanElement> | null | undefined;
24
- }) | undefined;
25
- primary?: ButtonProps | undefined;
26
- secondary?: ButtonProps | undefined;
27
- } | undefined;
28
- } | undefined;
29
- } & React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
43
+ export declare const Splitter: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
30
44
  export {};
@@ -0,0 +1,9 @@
1
+ import { ComponentProps } from 'react';
2
+ import { Splitter } from '../Splitter';
3
+ import './RangeAsPx.scss';
4
+ declare type SplitterProps = ComponentProps<typeof Splitter>;
5
+ declare type PixelProps = SplitterProps & {
6
+ unit?: '%' | 'px';
7
+ };
8
+ export declare const RangeAsPx: ({ unit, ...rest }: PixelProps) => JSX.Element;
9
+ export {};
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ declare type SectionProps = JSX.IntrinsicElements['section'];
3
+ export declare const HorizontalSection: (props: SectionProps) => JSX.Element;
4
+ export declare const VerticalSection: (props: SectionProps) => JSX.Element;
5
+ export {};
@@ -0,0 +1,18 @@
1
+ import { ComponentProps } from 'react';
2
+ import { Splitter } from '../Splitter';
3
+ declare type Props = Pick<ComponentProps<typeof Splitter>, 'min' | 'max'>;
4
+ declare type Result = 'keep-secondary' | 'keep-primary' | 'keep-both';
5
+ /**
6
+ * Given boundaries passed as prop, it defines how the grid column/row template will be arranged.
7
+ * and whether the separator will be positioned using right or left absolute values (top or bottom for horizontal).
8
+ * It will use a data- attribute to store this prop derived information for later processing.
9
+ */
10
+ export declare const setDataBoundary: (props: Props) => {
11
+ "data-boundary": Result;
12
+ };
13
+ /**
14
+ * Util to get what grid arrangement needs to be used to avoid jumps/flashes.
15
+ * The return value is derived from the Splitter props, and stored in a data- attribute.
16
+ */
17
+ export declare const getDataBoundary: (separator: Element) => Result | undefined;
18
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * It will calculate the best grid arrangement, based on the min/max props passed to the Splitter.
3
+ * All grid options work. The preference `1fr XXpx` over `(width - XXpx) 1fr` depends on the type of boundary
4
+ * to avoid calculation of position when the window is being resized while trying to retain the collapsed state
5
+ * on a min/max value fixed in pixels (e.g. 200px). Such calculation adds unnecessary lagging on the separator
6
+ * to catch up. This function aims to avoid such lagging during resizing.
7
+ * primary relates to top/left
8
+ * secondary relates to right/bottom
9
+ */
10
+ export declare const getGridTemplate: (separator: HTMLDivElement) => {
11
+ grid: string;
12
+ primary: string;
13
+ secondary: string;
14
+ };
@@ -21,5 +21,6 @@ export declare const getSeparatorAttributes: (props: Props) => {
21
21
  valueMax: number;
22
22
  orientation: "horizontal" | "vertical" | undefined;
23
23
  thickness: number;
24
+ boundary: ("keep-secondary" | "keep-primary" | "keep-both") | undefined;
24
25
  };
25
26
  export {};
@@ -0,0 +1,5 @@
1
+ import { RefObject } from 'react';
2
+ export declare const transition: (separator: RefObject<HTMLDivElement>) => {
3
+ stop: () => void;
4
+ resume: () => void;
5
+ };
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ declare type Boundary = {
3
+ min?: number | `${number}px`;
4
+ max?: number | `${number}px`;
5
+ };
6
+ /**
7
+ * Maps min and max values if they are provided in 'XXXpx' format.
8
+ */
9
+ export declare const useBoundary: (separator: React.RefObject<HTMLDivElement>, boundaries: Boundary) => {
10
+ min: number;
11
+ max: number;
12
+ };
13
+ export {};
@@ -5,7 +5,7 @@ import { RefObject } from 'react';
5
5
  * It's possible that multiple events trigger setValueNow simultaneosly with the same value.
6
6
  * This multiple calls are expected, and setValueNow will resize only once.
7
7
  */
8
- export declare const useValueSeparator: ({ separator, ratio, onResized, boundaries: { min, max }, }: {
8
+ export declare const useValueSeparator: ({ separator, ratio, onResized, boundaries: { min: minProp, max: maxProp }, startAt, }: {
9
9
  ratio?: number | undefined;
10
10
  onResized?: ((newVal: number) => void) | undefined;
11
11
  separator: RefObject<HTMLDivElement>;
@@ -13,6 +13,10 @@ export declare const useValueSeparator: ({ separator, ratio, onResized, boundari
13
13
  min: number;
14
14
  max: number;
15
15
  };
16
+ startAt?: number | undefined;
16
17
  }) => {
17
- setValueNow: (val?: number) => void;
18
+ setValueNow: (val?: number, config?: {
19
+ min?: number | undefined;
20
+ max?: number | undefined;
21
+ } | undefined) => void;
18
22
  };
@@ -2,4 +2,7 @@ import { RefObject } from 'react';
2
2
  /**
3
3
  * Calls setValueNow when the separator attributes change.
4
4
  */
5
- export declare const useValueSeparatorEffects: (setValueNow: (val?: number) => void, separator: RefObject<HTMLDivElement>, ratio?: number) => void;
5
+ export declare const useValueSeparatorEffects: (setValueNow: (val?: number, config?: {
6
+ min?: number;
7
+ max?: number;
8
+ }) => void, separator: RefObject<HTMLDivElement>, ratio?: number, startAt?: number) => void;