@pinfold/react 0.0.0-stage → 0.2.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 +58 -2
- package/accordion/lazy/package.json +6 -0
- package/accordion/package.json +6 -0
- package/dist/accordion/client.cjs +491 -0
- package/dist/accordion/client.d.cts +34 -0
- package/dist/accordion/client.d.ts +34 -0
- package/dist/accordion/client.js +490 -0
- package/dist/accordion/index.cjs +49 -0
- package/dist/accordion/index.d.cts +56 -0
- package/dist/accordion/index.d.ts +56 -0
- package/dist/accordion/index.js +14 -0
- package/dist/accordion/lazy.cjs +17 -0
- package/dist/accordion/lazy.d.cts +16 -0
- package/dist/accordion/lazy.d.ts +16 -0
- package/dist/accordion/lazy.js +16 -0
- package/dist/chunk-5ZMK623A.js +61 -0
- package/dist/chunk-BPPCPHHU.js +70 -0
- package/dist/chunk-DQWSDHRY.cjs +71 -0
- package/dist/chunk-Q232PTPW.js +115 -0
- package/dist/chunk-RJPT3NTP.cjs +62 -0
- package/dist/chunk-VPKVOJHA.cjs +116 -0
- package/dist/client.cjs +30 -0
- package/dist/client.d.cts +120 -0
- package/dist/client.d.ts +120 -0
- package/dist/client.js +29 -0
- package/dist/index.cjs +52 -0
- package/dist/index.d.cts +123 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +10 -0
- package/dist/types-CkcgnWwL.d.cts +367 -0
- package/dist/types-CkcgnWwL.d.ts +367 -0
- package/dist/types-N0Yo4zGa.d.cts +374 -0
- package/dist/types-N0Yo4zGa.d.ts +374 -0
- package/dist/validate-EQHBH4NH.cjs +42 -0
- package/dist/validate-WKHQNNGD.js +41 -0
- package/llms-full.txt +140 -0
- package/llms.txt +26 -0
- package/package.json +92 -4
- package/registry/accordion.json +20 -0
- package/registry/registry.json +25 -0
- package/schema/accordion.json +903 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PinfoldTheme, PinfoldRadius, PinfoldDir, PinfoldSize, PinfoldTone, PinfoldStylePack, PinfoldLazy, PropsBag } from '@pinfold/core';
|
|
3
|
+
import { d as AccordionOptions, S as SlotOverrides } from './types-CkcgnWwL.cjs';
|
|
4
|
+
export { P as PinfoldComponent, e as SlotRenderer, f as Slottable, u as usePinfoldComponent } from './types-CkcgnWwL.cjs';
|
|
5
|
+
|
|
6
|
+
/** Per-component defaults. Data, state and ids never belong here, only how components look and behave. */
|
|
7
|
+
interface PinfoldComponentDefaults {
|
|
8
|
+
accordion?: Omit<AccordionOptions, 'value' | 'defaultValue' | 'disabledIds' | 'id'>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The global config, usually in `pinfold.config.ts` (or `.js`):
|
|
12
|
+
*
|
|
13
|
+
* export default defineConfig({ theme: 'system', radius: 'lg', defaults: { accordion: { variant: 'separated' } } });
|
|
14
|
+
*
|
|
15
|
+
* and handed to the provider once: `<PinfoldProvider config={config}>`.
|
|
16
|
+
* Precedence, highest first: component config, `defaults.<component>`, this
|
|
17
|
+
* global theme, the library defaults. A nested provider overrides its section.
|
|
18
|
+
*/
|
|
19
|
+
interface PinfoldConfig {
|
|
20
|
+
theme?: PinfoldTheme;
|
|
21
|
+
radius?: PinfoldRadius;
|
|
22
|
+
dir?: PinfoldDir;
|
|
23
|
+
size?: PinfoldSize;
|
|
24
|
+
tone?: PinfoldTone;
|
|
25
|
+
/** Visual style pack (needs `@pinfold/css/packs.css`). Default `'default'`. */
|
|
26
|
+
stylePack?: PinfoldStylePack;
|
|
27
|
+
/** Default code-loading strategy for `/lazy` entries. Default `'auto'`. */
|
|
28
|
+
lazy?: PinfoldLazy;
|
|
29
|
+
/** Disable every component transition, e.g. in tests or on low-power devices. */
|
|
30
|
+
disableAnimation?: boolean;
|
|
31
|
+
defaults?: PinfoldComponentDefaults;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface PinfoldContextValue {
|
|
35
|
+
theme: PinfoldTheme;
|
|
36
|
+
radius: PinfoldRadius;
|
|
37
|
+
dir: PinfoldDir;
|
|
38
|
+
size: PinfoldSize;
|
|
39
|
+
tone: PinfoldTone;
|
|
40
|
+
stylePack: PinfoldStylePack;
|
|
41
|
+
lazy: PinfoldLazy;
|
|
42
|
+
/** Disable every component transition, e.g. in tests or on low-power devices. */
|
|
43
|
+
disableAnimation: boolean;
|
|
44
|
+
defaults: PinfoldComponentDefaults;
|
|
45
|
+
}
|
|
46
|
+
/** Component-level defaults. Every component calls this; the provider is optional. */
|
|
47
|
+
declare function usePinfold(): PinfoldContextValue;
|
|
48
|
+
interface PinfoldProviderProps extends PinfoldConfig {
|
|
49
|
+
children?: React.ReactNode;
|
|
50
|
+
/** A whole config from `defineConfig()`. Individual props override it. */
|
|
51
|
+
config?: PinfoldConfig;
|
|
52
|
+
/**
|
|
53
|
+
* Write `data-pinfold-theme` / `data-pinfold-radius` / `data-pinfold-style`
|
|
54
|
+
* onto `<html>` instead of a wrapper element. Use this when portals
|
|
55
|
+
* (dialogs, tooltips) must inherit the theme. Default: false.
|
|
56
|
+
*/
|
|
57
|
+
applyToDocument?: boolean;
|
|
58
|
+
className?: string;
|
|
59
|
+
}
|
|
60
|
+
declare function PinfoldProvider(props: PinfoldProviderProps): React.ReactElement;
|
|
61
|
+
|
|
62
|
+
/** SSR-safe layout effect. */
|
|
63
|
+
declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
|
|
64
|
+
/**
|
|
65
|
+
* Stable, SSR-safe id (React 18+ `useId`). The characters React wraps ids in
|
|
66
|
+
* (`:` in 18, `«»` in 19) are stripped so the id is also a valid CSS selector.
|
|
67
|
+
*/
|
|
68
|
+
declare function useId(provided?: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* A callback whose identity never changes but which always sees fresh props.
|
|
71
|
+
* Lets us hand stable handlers to consumers without re-render churn.
|
|
72
|
+
*/
|
|
73
|
+
declare function useEvent<T extends (...args: any[]) => any>(fn: T): T;
|
|
74
|
+
interface ControllableStateOptions<T> {
|
|
75
|
+
value?: T;
|
|
76
|
+
defaultValue: T | (() => T);
|
|
77
|
+
onChange?: (value: T) => void;
|
|
78
|
+
}
|
|
79
|
+
/** One state hook that is controlled, uncontrolled, or both. */
|
|
80
|
+
declare function useControllableState<T>({ value, defaultValue, onChange, }: ControllableStateOptions<T>): [T, (next: T | ((prev: T) => T)) => void];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Fold a slot's `classNames`, `styles` and `slotProps` overrides into the
|
|
84
|
+
* behaviour props a component generated. Handlers chain, classes concatenate,
|
|
85
|
+
* styles merge.
|
|
86
|
+
*/
|
|
87
|
+
declare function slotProps<Slot extends string, State>(overrides: SlotOverrides<Slot, State> | undefined, slot: Slot, base: PropsBag): PropsBag;
|
|
88
|
+
/**
|
|
89
|
+
* Render a slot, letting the consumer swap the element while keeping every
|
|
90
|
+
* accessibility prop. `defaultRender` is used when no override exists.
|
|
91
|
+
*/
|
|
92
|
+
declare function renderSlot<Slot extends string, State>(overrides: SlotOverrides<Slot, State> | undefined, slot: Slot, props: PropsBag, state: State, children: React.ReactNode, defaultRender: (props: PropsBag, children: React.ReactNode) => React.ReactNode): React.ReactNode;
|
|
93
|
+
|
|
94
|
+
interface LazyOptions {
|
|
95
|
+
/** Rendered while the chunk downloads, and in the placeholder. Default: nothing. */
|
|
96
|
+
fallback?: React.ReactNode;
|
|
97
|
+
/** Name shown in React DevTools. */
|
|
98
|
+
displayName?: string;
|
|
99
|
+
/** What `lazy: 'auto'` means for this component: `eager` when light, `visible` when heavy. Default `eager`. */
|
|
100
|
+
auto?: Exclude<PinfoldLazy, 'auto'>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Wrap a dynamic import into a drop-in component with its own Suspense
|
|
104
|
+
* boundary, so consumers get code-splitting without touching their tree:
|
|
105
|
+
*
|
|
106
|
+
* const Accordion = createLazyComponent(() => import('@pinfold/react/accordion'));
|
|
107
|
+
* <Accordion items={items} lazy="visible" />
|
|
108
|
+
*
|
|
109
|
+
* `lazy` (prop, else the provider): `eager` loads at once, `visible` when the
|
|
110
|
+
* placeholder nears the viewport, `idle` when the browser is idle. Lazy entries
|
|
111
|
+
* render on the client; for complete server HTML use the main entry.
|
|
112
|
+
*/
|
|
113
|
+
declare function createLazyComponent<P extends object>(loader: () => Promise<{
|
|
114
|
+
default: React.ComponentType<P>;
|
|
115
|
+
}>, options?: LazyOptions): React.ComponentType<P & {
|
|
116
|
+
lazy?: PinfoldLazy;
|
|
117
|
+
}>;
|
|
118
|
+
|
|
119
|
+
export { PinfoldProvider, SlotOverrides, createLazyComponent, renderSlot, slotProps, useControllableState, useEvent, useId, useIsomorphicLayoutEffect, usePinfold };
|
|
120
|
+
export type { ControllableStateOptions, LazyOptions, PinfoldContextValue, PinfoldProviderProps };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PinfoldTheme, PinfoldRadius, PinfoldDir, PinfoldSize, PinfoldTone, PinfoldStylePack, PinfoldLazy, PropsBag } from '@pinfold/core';
|
|
3
|
+
import { d as AccordionOptions, S as SlotOverrides } from './types-CkcgnWwL.js';
|
|
4
|
+
export { P as PinfoldComponent, e as SlotRenderer, f as Slottable, u as usePinfoldComponent } from './types-CkcgnWwL.js';
|
|
5
|
+
|
|
6
|
+
/** Per-component defaults. Data, state and ids never belong here, only how components look and behave. */
|
|
7
|
+
interface PinfoldComponentDefaults {
|
|
8
|
+
accordion?: Omit<AccordionOptions, 'value' | 'defaultValue' | 'disabledIds' | 'id'>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The global config, usually in `pinfold.config.ts` (or `.js`):
|
|
12
|
+
*
|
|
13
|
+
* export default defineConfig({ theme: 'system', radius: 'lg', defaults: { accordion: { variant: 'separated' } } });
|
|
14
|
+
*
|
|
15
|
+
* and handed to the provider once: `<PinfoldProvider config={config}>`.
|
|
16
|
+
* Precedence, highest first: component config, `defaults.<component>`, this
|
|
17
|
+
* global theme, the library defaults. A nested provider overrides its section.
|
|
18
|
+
*/
|
|
19
|
+
interface PinfoldConfig {
|
|
20
|
+
theme?: PinfoldTheme;
|
|
21
|
+
radius?: PinfoldRadius;
|
|
22
|
+
dir?: PinfoldDir;
|
|
23
|
+
size?: PinfoldSize;
|
|
24
|
+
tone?: PinfoldTone;
|
|
25
|
+
/** Visual style pack (needs `@pinfold/css/packs.css`). Default `'default'`. */
|
|
26
|
+
stylePack?: PinfoldStylePack;
|
|
27
|
+
/** Default code-loading strategy for `/lazy` entries. Default `'auto'`. */
|
|
28
|
+
lazy?: PinfoldLazy;
|
|
29
|
+
/** Disable every component transition, e.g. in tests or on low-power devices. */
|
|
30
|
+
disableAnimation?: boolean;
|
|
31
|
+
defaults?: PinfoldComponentDefaults;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface PinfoldContextValue {
|
|
35
|
+
theme: PinfoldTheme;
|
|
36
|
+
radius: PinfoldRadius;
|
|
37
|
+
dir: PinfoldDir;
|
|
38
|
+
size: PinfoldSize;
|
|
39
|
+
tone: PinfoldTone;
|
|
40
|
+
stylePack: PinfoldStylePack;
|
|
41
|
+
lazy: PinfoldLazy;
|
|
42
|
+
/** Disable every component transition, e.g. in tests or on low-power devices. */
|
|
43
|
+
disableAnimation: boolean;
|
|
44
|
+
defaults: PinfoldComponentDefaults;
|
|
45
|
+
}
|
|
46
|
+
/** Component-level defaults. Every component calls this; the provider is optional. */
|
|
47
|
+
declare function usePinfold(): PinfoldContextValue;
|
|
48
|
+
interface PinfoldProviderProps extends PinfoldConfig {
|
|
49
|
+
children?: React.ReactNode;
|
|
50
|
+
/** A whole config from `defineConfig()`. Individual props override it. */
|
|
51
|
+
config?: PinfoldConfig;
|
|
52
|
+
/**
|
|
53
|
+
* Write `data-pinfold-theme` / `data-pinfold-radius` / `data-pinfold-style`
|
|
54
|
+
* onto `<html>` instead of a wrapper element. Use this when portals
|
|
55
|
+
* (dialogs, tooltips) must inherit the theme. Default: false.
|
|
56
|
+
*/
|
|
57
|
+
applyToDocument?: boolean;
|
|
58
|
+
className?: string;
|
|
59
|
+
}
|
|
60
|
+
declare function PinfoldProvider(props: PinfoldProviderProps): React.ReactElement;
|
|
61
|
+
|
|
62
|
+
/** SSR-safe layout effect. */
|
|
63
|
+
declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
|
|
64
|
+
/**
|
|
65
|
+
* Stable, SSR-safe id (React 18+ `useId`). The characters React wraps ids in
|
|
66
|
+
* (`:` in 18, `«»` in 19) are stripped so the id is also a valid CSS selector.
|
|
67
|
+
*/
|
|
68
|
+
declare function useId(provided?: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* A callback whose identity never changes but which always sees fresh props.
|
|
71
|
+
* Lets us hand stable handlers to consumers without re-render churn.
|
|
72
|
+
*/
|
|
73
|
+
declare function useEvent<T extends (...args: any[]) => any>(fn: T): T;
|
|
74
|
+
interface ControllableStateOptions<T> {
|
|
75
|
+
value?: T;
|
|
76
|
+
defaultValue: T | (() => T);
|
|
77
|
+
onChange?: (value: T) => void;
|
|
78
|
+
}
|
|
79
|
+
/** One state hook that is controlled, uncontrolled, or both. */
|
|
80
|
+
declare function useControllableState<T>({ value, defaultValue, onChange, }: ControllableStateOptions<T>): [T, (next: T | ((prev: T) => T)) => void];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Fold a slot's `classNames`, `styles` and `slotProps` overrides into the
|
|
84
|
+
* behaviour props a component generated. Handlers chain, classes concatenate,
|
|
85
|
+
* styles merge.
|
|
86
|
+
*/
|
|
87
|
+
declare function slotProps<Slot extends string, State>(overrides: SlotOverrides<Slot, State> | undefined, slot: Slot, base: PropsBag): PropsBag;
|
|
88
|
+
/**
|
|
89
|
+
* Render a slot, letting the consumer swap the element while keeping every
|
|
90
|
+
* accessibility prop. `defaultRender` is used when no override exists.
|
|
91
|
+
*/
|
|
92
|
+
declare function renderSlot<Slot extends string, State>(overrides: SlotOverrides<Slot, State> | undefined, slot: Slot, props: PropsBag, state: State, children: React.ReactNode, defaultRender: (props: PropsBag, children: React.ReactNode) => React.ReactNode): React.ReactNode;
|
|
93
|
+
|
|
94
|
+
interface LazyOptions {
|
|
95
|
+
/** Rendered while the chunk downloads, and in the placeholder. Default: nothing. */
|
|
96
|
+
fallback?: React.ReactNode;
|
|
97
|
+
/** Name shown in React DevTools. */
|
|
98
|
+
displayName?: string;
|
|
99
|
+
/** What `lazy: 'auto'` means for this component: `eager` when light, `visible` when heavy. Default `eager`. */
|
|
100
|
+
auto?: Exclude<PinfoldLazy, 'auto'>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Wrap a dynamic import into a drop-in component with its own Suspense
|
|
104
|
+
* boundary, so consumers get code-splitting without touching their tree:
|
|
105
|
+
*
|
|
106
|
+
* const Accordion = createLazyComponent(() => import('@pinfold/react/accordion'));
|
|
107
|
+
* <Accordion items={items} lazy="visible" />
|
|
108
|
+
*
|
|
109
|
+
* `lazy` (prop, else the provider): `eager` loads at once, `visible` when the
|
|
110
|
+
* placeholder nears the viewport, `idle` when the browser is idle. Lazy entries
|
|
111
|
+
* render on the client; for complete server HTML use the main entry.
|
|
112
|
+
*/
|
|
113
|
+
declare function createLazyComponent<P extends object>(loader: () => Promise<{
|
|
114
|
+
default: React.ComponentType<P>;
|
|
115
|
+
}>, options?: LazyOptions): React.ComponentType<P & {
|
|
116
|
+
lazy?: PinfoldLazy;
|
|
117
|
+
}>;
|
|
118
|
+
|
|
119
|
+
export { PinfoldProvider, SlotOverrides, createLazyComponent, renderSlot, slotProps, useControllableState, useEvent, useId, useIsomorphicLayoutEffect, usePinfold };
|
|
120
|
+
export type { ControllableStateOptions, LazyOptions, PinfoldContextValue, PinfoldProviderProps };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
renderSlot,
|
|
4
|
+
slotProps,
|
|
5
|
+
usePinfoldComponent
|
|
6
|
+
} from "./chunk-BPPCPHHU.js";
|
|
7
|
+
import {
|
|
8
|
+
createLazyComponent
|
|
9
|
+
} from "./chunk-5ZMK623A.js";
|
|
10
|
+
import {
|
|
11
|
+
PinfoldProvider,
|
|
12
|
+
useControllableState,
|
|
13
|
+
useEvent,
|
|
14
|
+
useId,
|
|
15
|
+
useIsomorphicLayoutEffect,
|
|
16
|
+
usePinfold
|
|
17
|
+
} from "./chunk-Q232PTPW.js";
|
|
18
|
+
export {
|
|
19
|
+
PinfoldProvider,
|
|
20
|
+
createLazyComponent,
|
|
21
|
+
renderSlot,
|
|
22
|
+
slotProps,
|
|
23
|
+
useControllableState,
|
|
24
|
+
useEvent,
|
|
25
|
+
useId,
|
|
26
|
+
useIsomorphicLayoutEffect,
|
|
27
|
+
usePinfold,
|
|
28
|
+
usePinfoldComponent
|
|
29
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client_cjs = require('./client.cjs');
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
|
|
7
|
+
// src/config.ts
|
|
8
|
+
function defineConfig(config) {
|
|
9
|
+
return config;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, "PinfoldProvider", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return client_cjs.PinfoldProvider; }
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "createLazyComponent", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return client_cjs.createLazyComponent; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "renderSlot", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return client_cjs.renderSlot; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "slotProps", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return client_cjs.slotProps; }
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "useControllableState", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return client_cjs.useControllableState; }
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "useEvent", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return client_cjs.useEvent; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "useId", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return client_cjs.useId; }
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "useIsomorphicLayoutEffect", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return client_cjs.useIsomorphicLayoutEffect; }
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, "usePinfold", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () { return client_cjs.usePinfold; }
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "usePinfoldComponent", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () { return client_cjs.usePinfoldComponent; }
|
|
51
|
+
});
|
|
52
|
+
exports.defineConfig = defineConfig;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PinfoldTheme, PinfoldRadius, PinfoldDir, PinfoldSize, PinfoldTone, PinfoldStylePack, PinfoldLazy, PropsBag } from '@pinfold/core';
|
|
3
|
+
import { S as SlotOverrides } from './types-N0Yo4zGa.cjs';
|
|
4
|
+
import { AccordionOptions } from './accordion/index.cjs';
|
|
5
|
+
export { P as PinfoldComponent, w as SlotRenderer, x as Slottable, y as usePinfoldComponent } from './types-N0Yo4zGa.cjs';
|
|
6
|
+
|
|
7
|
+
/** Per-component defaults. Data, state and ids never belong here, only how components look and behave. */
|
|
8
|
+
interface PinfoldComponentDefaults {
|
|
9
|
+
accordion?: Omit<AccordionOptions, 'value' | 'defaultValue' | 'disabledIds' | 'id'>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The global config, usually in `pinfold.config.ts` (or `.js`):
|
|
13
|
+
*
|
|
14
|
+
* export default defineConfig({ theme: 'system', radius: 'lg', defaults: { accordion: { variant: 'separated' } } });
|
|
15
|
+
*
|
|
16
|
+
* and handed to the provider once: `<PinfoldProvider config={config}>`.
|
|
17
|
+
* Precedence, highest first: component config, `defaults.<component>`, this
|
|
18
|
+
* global theme, the library defaults. A nested provider overrides its section.
|
|
19
|
+
*/
|
|
20
|
+
interface PinfoldConfig {
|
|
21
|
+
theme?: PinfoldTheme;
|
|
22
|
+
radius?: PinfoldRadius;
|
|
23
|
+
dir?: PinfoldDir;
|
|
24
|
+
size?: PinfoldSize;
|
|
25
|
+
tone?: PinfoldTone;
|
|
26
|
+
/** Visual style pack (needs `@pinfold/css/packs.css`). Default `'default'`. */
|
|
27
|
+
stylePack?: PinfoldStylePack;
|
|
28
|
+
/** Default code-loading strategy for `/lazy` entries. Default `'auto'`. */
|
|
29
|
+
lazy?: PinfoldLazy;
|
|
30
|
+
/** Disable every component transition, e.g. in tests or on low-power devices. */
|
|
31
|
+
disableAnimation?: boolean;
|
|
32
|
+
defaults?: PinfoldComponentDefaults;
|
|
33
|
+
}
|
|
34
|
+
/** Identity function that types a global config. Safe to call from Server Components. */
|
|
35
|
+
declare function defineConfig<T extends PinfoldConfig>(config: T): T;
|
|
36
|
+
|
|
37
|
+
interface PinfoldContextValue {
|
|
38
|
+
theme: PinfoldTheme;
|
|
39
|
+
radius: PinfoldRadius;
|
|
40
|
+
dir: PinfoldDir;
|
|
41
|
+
size: PinfoldSize;
|
|
42
|
+
tone: PinfoldTone;
|
|
43
|
+
stylePack: PinfoldStylePack;
|
|
44
|
+
lazy: PinfoldLazy;
|
|
45
|
+
/** Disable every component transition, e.g. in tests or on low-power devices. */
|
|
46
|
+
disableAnimation: boolean;
|
|
47
|
+
defaults: PinfoldComponentDefaults;
|
|
48
|
+
}
|
|
49
|
+
/** Component-level defaults. Every component calls this; the provider is optional. */
|
|
50
|
+
declare function usePinfold(): PinfoldContextValue;
|
|
51
|
+
interface PinfoldProviderProps extends PinfoldConfig {
|
|
52
|
+
children?: React.ReactNode;
|
|
53
|
+
/** A whole config from `defineConfig()`. Individual props override it. */
|
|
54
|
+
config?: PinfoldConfig;
|
|
55
|
+
/**
|
|
56
|
+
* Write `data-pinfold-theme` / `data-pinfold-radius` / `data-pinfold-style`
|
|
57
|
+
* onto `<html>` instead of a wrapper element. Use this when portals
|
|
58
|
+
* (dialogs, tooltips) must inherit the theme. Default: false.
|
|
59
|
+
*/
|
|
60
|
+
applyToDocument?: boolean;
|
|
61
|
+
className?: string;
|
|
62
|
+
}
|
|
63
|
+
declare function PinfoldProvider(props: PinfoldProviderProps): React.ReactElement;
|
|
64
|
+
|
|
65
|
+
/** SSR-safe layout effect. */
|
|
66
|
+
declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
|
|
67
|
+
/**
|
|
68
|
+
* Stable, SSR-safe id (React 18+ `useId`). The characters React wraps ids in
|
|
69
|
+
* (`:` in 18, `«»` in 19) are stripped so the id is also a valid CSS selector.
|
|
70
|
+
*/
|
|
71
|
+
declare function useId(provided?: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* A callback whose identity never changes but which always sees fresh props.
|
|
74
|
+
* Lets us hand stable handlers to consumers without re-render churn.
|
|
75
|
+
*/
|
|
76
|
+
declare function useEvent<T extends (...args: any[]) => any>(fn: T): T;
|
|
77
|
+
interface ControllableStateOptions<T> {
|
|
78
|
+
value?: T;
|
|
79
|
+
defaultValue: T | (() => T);
|
|
80
|
+
onChange?: (value: T) => void;
|
|
81
|
+
}
|
|
82
|
+
/** One state hook that is controlled, uncontrolled, or both. */
|
|
83
|
+
declare function useControllableState<T>({ value, defaultValue, onChange, }: ControllableStateOptions<T>): [T, (next: T | ((prev: T) => T)) => void];
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Fold a slot's `classNames`, `styles` and `slotProps` overrides into the
|
|
87
|
+
* behaviour props a component generated. Handlers chain, classes concatenate,
|
|
88
|
+
* styles merge.
|
|
89
|
+
*/
|
|
90
|
+
declare function slotProps<Slot extends string, State>(overrides: SlotOverrides<Slot, State> | undefined, slot: Slot, base: PropsBag): PropsBag;
|
|
91
|
+
/**
|
|
92
|
+
* Render a slot, letting the consumer swap the element while keeping every
|
|
93
|
+
* accessibility prop. `defaultRender` is used when no override exists.
|
|
94
|
+
*/
|
|
95
|
+
declare function renderSlot<Slot extends string, State>(overrides: SlotOverrides<Slot, State> | undefined, slot: Slot, props: PropsBag, state: State, children: React.ReactNode, defaultRender: (props: PropsBag, children: React.ReactNode) => React.ReactNode): React.ReactNode;
|
|
96
|
+
|
|
97
|
+
interface LazyOptions {
|
|
98
|
+
/** Rendered while the chunk downloads, and in the placeholder. Default: nothing. */
|
|
99
|
+
fallback?: React.ReactNode;
|
|
100
|
+
/** Name shown in React DevTools. */
|
|
101
|
+
displayName?: string;
|
|
102
|
+
/** What `lazy: 'auto'` means for this component: `eager` when light, `visible` when heavy. Default `eager`. */
|
|
103
|
+
auto?: Exclude<PinfoldLazy, 'auto'>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Wrap a dynamic import into a drop-in component with its own Suspense
|
|
107
|
+
* boundary, so consumers get code-splitting without touching their tree:
|
|
108
|
+
*
|
|
109
|
+
* const Accordion = createLazyComponent(() => import('@pinfold/react/accordion'));
|
|
110
|
+
* <Accordion items={items} lazy="visible" />
|
|
111
|
+
*
|
|
112
|
+
* `lazy` (prop, else the provider): `eager` loads at once, `visible` when the
|
|
113
|
+
* placeholder nears the viewport, `idle` when the browser is idle. Lazy entries
|
|
114
|
+
* render on the client; for complete server HTML use the main entry.
|
|
115
|
+
*/
|
|
116
|
+
declare function createLazyComponent<P extends object>(loader: () => Promise<{
|
|
117
|
+
default: React.ComponentType<P>;
|
|
118
|
+
}>, options?: LazyOptions): React.ComponentType<P & {
|
|
119
|
+
lazy?: PinfoldLazy;
|
|
120
|
+
}>;
|
|
121
|
+
|
|
122
|
+
export { PinfoldProvider, SlotOverrides, createLazyComponent, defineConfig, renderSlot, slotProps, useControllableState, useEvent, useId, useIsomorphicLayoutEffect, usePinfold };
|
|
123
|
+
export type { ControllableStateOptions, LazyOptions, PinfoldComponentDefaults, PinfoldConfig, PinfoldContextValue, PinfoldProviderProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PinfoldTheme, PinfoldRadius, PinfoldDir, PinfoldSize, PinfoldTone, PinfoldStylePack, PinfoldLazy, PropsBag } from '@pinfold/core';
|
|
3
|
+
import { S as SlotOverrides } from './types-N0Yo4zGa.js';
|
|
4
|
+
import { AccordionOptions } from './accordion/index.js';
|
|
5
|
+
export { P as PinfoldComponent, w as SlotRenderer, x as Slottable, y as usePinfoldComponent } from './types-N0Yo4zGa.js';
|
|
6
|
+
|
|
7
|
+
/** Per-component defaults. Data, state and ids never belong here, only how components look and behave. */
|
|
8
|
+
interface PinfoldComponentDefaults {
|
|
9
|
+
accordion?: Omit<AccordionOptions, 'value' | 'defaultValue' | 'disabledIds' | 'id'>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The global config, usually in `pinfold.config.ts` (or `.js`):
|
|
13
|
+
*
|
|
14
|
+
* export default defineConfig({ theme: 'system', radius: 'lg', defaults: { accordion: { variant: 'separated' } } });
|
|
15
|
+
*
|
|
16
|
+
* and handed to the provider once: `<PinfoldProvider config={config}>`.
|
|
17
|
+
* Precedence, highest first: component config, `defaults.<component>`, this
|
|
18
|
+
* global theme, the library defaults. A nested provider overrides its section.
|
|
19
|
+
*/
|
|
20
|
+
interface PinfoldConfig {
|
|
21
|
+
theme?: PinfoldTheme;
|
|
22
|
+
radius?: PinfoldRadius;
|
|
23
|
+
dir?: PinfoldDir;
|
|
24
|
+
size?: PinfoldSize;
|
|
25
|
+
tone?: PinfoldTone;
|
|
26
|
+
/** Visual style pack (needs `@pinfold/css/packs.css`). Default `'default'`. */
|
|
27
|
+
stylePack?: PinfoldStylePack;
|
|
28
|
+
/** Default code-loading strategy for `/lazy` entries. Default `'auto'`. */
|
|
29
|
+
lazy?: PinfoldLazy;
|
|
30
|
+
/** Disable every component transition, e.g. in tests or on low-power devices. */
|
|
31
|
+
disableAnimation?: boolean;
|
|
32
|
+
defaults?: PinfoldComponentDefaults;
|
|
33
|
+
}
|
|
34
|
+
/** Identity function that types a global config. Safe to call from Server Components. */
|
|
35
|
+
declare function defineConfig<T extends PinfoldConfig>(config: T): T;
|
|
36
|
+
|
|
37
|
+
interface PinfoldContextValue {
|
|
38
|
+
theme: PinfoldTheme;
|
|
39
|
+
radius: PinfoldRadius;
|
|
40
|
+
dir: PinfoldDir;
|
|
41
|
+
size: PinfoldSize;
|
|
42
|
+
tone: PinfoldTone;
|
|
43
|
+
stylePack: PinfoldStylePack;
|
|
44
|
+
lazy: PinfoldLazy;
|
|
45
|
+
/** Disable every component transition, e.g. in tests or on low-power devices. */
|
|
46
|
+
disableAnimation: boolean;
|
|
47
|
+
defaults: PinfoldComponentDefaults;
|
|
48
|
+
}
|
|
49
|
+
/** Component-level defaults. Every component calls this; the provider is optional. */
|
|
50
|
+
declare function usePinfold(): PinfoldContextValue;
|
|
51
|
+
interface PinfoldProviderProps extends PinfoldConfig {
|
|
52
|
+
children?: React.ReactNode;
|
|
53
|
+
/** A whole config from `defineConfig()`. Individual props override it. */
|
|
54
|
+
config?: PinfoldConfig;
|
|
55
|
+
/**
|
|
56
|
+
* Write `data-pinfold-theme` / `data-pinfold-radius` / `data-pinfold-style`
|
|
57
|
+
* onto `<html>` instead of a wrapper element. Use this when portals
|
|
58
|
+
* (dialogs, tooltips) must inherit the theme. Default: false.
|
|
59
|
+
*/
|
|
60
|
+
applyToDocument?: boolean;
|
|
61
|
+
className?: string;
|
|
62
|
+
}
|
|
63
|
+
declare function PinfoldProvider(props: PinfoldProviderProps): React.ReactElement;
|
|
64
|
+
|
|
65
|
+
/** SSR-safe layout effect. */
|
|
66
|
+
declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
|
|
67
|
+
/**
|
|
68
|
+
* Stable, SSR-safe id (React 18+ `useId`). The characters React wraps ids in
|
|
69
|
+
* (`:` in 18, `«»` in 19) are stripped so the id is also a valid CSS selector.
|
|
70
|
+
*/
|
|
71
|
+
declare function useId(provided?: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* A callback whose identity never changes but which always sees fresh props.
|
|
74
|
+
* Lets us hand stable handlers to consumers without re-render churn.
|
|
75
|
+
*/
|
|
76
|
+
declare function useEvent<T extends (...args: any[]) => any>(fn: T): T;
|
|
77
|
+
interface ControllableStateOptions<T> {
|
|
78
|
+
value?: T;
|
|
79
|
+
defaultValue: T | (() => T);
|
|
80
|
+
onChange?: (value: T) => void;
|
|
81
|
+
}
|
|
82
|
+
/** One state hook that is controlled, uncontrolled, or both. */
|
|
83
|
+
declare function useControllableState<T>({ value, defaultValue, onChange, }: ControllableStateOptions<T>): [T, (next: T | ((prev: T) => T)) => void];
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Fold a slot's `classNames`, `styles` and `slotProps` overrides into the
|
|
87
|
+
* behaviour props a component generated. Handlers chain, classes concatenate,
|
|
88
|
+
* styles merge.
|
|
89
|
+
*/
|
|
90
|
+
declare function slotProps<Slot extends string, State>(overrides: SlotOverrides<Slot, State> | undefined, slot: Slot, base: PropsBag): PropsBag;
|
|
91
|
+
/**
|
|
92
|
+
* Render a slot, letting the consumer swap the element while keeping every
|
|
93
|
+
* accessibility prop. `defaultRender` is used when no override exists.
|
|
94
|
+
*/
|
|
95
|
+
declare function renderSlot<Slot extends string, State>(overrides: SlotOverrides<Slot, State> | undefined, slot: Slot, props: PropsBag, state: State, children: React.ReactNode, defaultRender: (props: PropsBag, children: React.ReactNode) => React.ReactNode): React.ReactNode;
|
|
96
|
+
|
|
97
|
+
interface LazyOptions {
|
|
98
|
+
/** Rendered while the chunk downloads, and in the placeholder. Default: nothing. */
|
|
99
|
+
fallback?: React.ReactNode;
|
|
100
|
+
/** Name shown in React DevTools. */
|
|
101
|
+
displayName?: string;
|
|
102
|
+
/** What `lazy: 'auto'` means for this component: `eager` when light, `visible` when heavy. Default `eager`. */
|
|
103
|
+
auto?: Exclude<PinfoldLazy, 'auto'>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Wrap a dynamic import into a drop-in component with its own Suspense
|
|
107
|
+
* boundary, so consumers get code-splitting without touching their tree:
|
|
108
|
+
*
|
|
109
|
+
* const Accordion = createLazyComponent(() => import('@pinfold/react/accordion'));
|
|
110
|
+
* <Accordion items={items} lazy="visible" />
|
|
111
|
+
*
|
|
112
|
+
* `lazy` (prop, else the provider): `eager` loads at once, `visible` when the
|
|
113
|
+
* placeholder nears the viewport, `idle` when the browser is idle. Lazy entries
|
|
114
|
+
* render on the client; for complete server HTML use the main entry.
|
|
115
|
+
*/
|
|
116
|
+
declare function createLazyComponent<P extends object>(loader: () => Promise<{
|
|
117
|
+
default: React.ComponentType<P>;
|
|
118
|
+
}>, options?: LazyOptions): React.ComponentType<P & {
|
|
119
|
+
lazy?: PinfoldLazy;
|
|
120
|
+
}>;
|
|
121
|
+
|
|
122
|
+
export { PinfoldProvider, SlotOverrides, createLazyComponent, defineConfig, renderSlot, slotProps, useControllableState, useEvent, useId, useIsomorphicLayoutEffect, usePinfold };
|
|
123
|
+
export type { ControllableStateOptions, LazyOptions, PinfoldComponentDefaults, PinfoldConfig, PinfoldContextValue, PinfoldProviderProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { PinfoldProvider, createLazyComponent, renderSlot, slotProps, useControllableState, useEvent, useId, useIsomorphicLayoutEffect, usePinfold, usePinfoldComponent } from './client.js';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
|
|
5
|
+
// src/config.ts
|
|
6
|
+
function defineConfig(config) {
|
|
7
|
+
return config;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { defineConfig };
|