foldkit 0.25.0 → 0.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/README.md +70 -55
- package/dist/fieldValidation/index.d.ts +39 -29
- package/dist/fieldValidation/index.d.ts.map +1 -1
- package/dist/fieldValidation/index.js +23 -24
- package/dist/fieldValidation/public.d.ts +2 -2
- package/dist/fieldValidation/public.d.ts.map +1 -1
- package/dist/fieldValidation/public.js +1 -1
- package/dist/html/index.d.ts +2 -9
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/public.d.ts +1 -1
- package/dist/html/public.d.ts.map +1 -1
- package/dist/ui/anchor.d.ts +19 -0
- package/dist/ui/anchor.d.ts.map +1 -0
- package/dist/ui/{menu/anchor.js → anchor.js} +3 -2
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +2 -0
- package/dist/ui/listbox/public.d.ts +3 -2
- package/dist/ui/listbox/public.d.ts.map +1 -1
- package/dist/ui/listbox/public.js +2 -1
- package/dist/ui/listbox/shared.d.ts +1 -4
- package/dist/ui/listbox/shared.d.ts.map +1 -1
- package/dist/ui/listbox/shared.js +2 -3
- package/dist/ui/menu/index.d.ts +1 -4
- package/dist/ui/menu/index.d.ts.map +1 -1
- package/dist/ui/menu/index.js +2 -3
- package/dist/ui/menu/public.d.ts +3 -2
- package/dist/ui/menu/public.d.ts.map +1 -1
- package/dist/ui/menu/public.js +2 -1
- package/dist/ui/popover/index.d.ts +75 -0
- package/dist/ui/popover/index.d.ts.map +1 -0
- package/dist/ui/popover/index.js +237 -0
- package/dist/ui/popover/public.d.ts +5 -0
- package/dist/ui/popover/public.d.ts.map +1 -0
- package/dist/ui/popover/public.js +2 -0
- package/dist/ui/switch/index.d.ts +47 -0
- package/dist/ui/switch/index.d.ts.map +1 -0
- package/dist/ui/switch/index.js +66 -0
- package/dist/ui/switch/public.d.ts +3 -0
- package/dist/ui/switch/public.d.ts.map +1 -0
- package/dist/ui/switch/public.js +1 -0
- package/dist/ui/transition.d.ts +5 -0
- package/dist/ui/transition.d.ts.map +1 -0
- package/dist/ui/transition.js +3 -0
- package/package.json +9 -1
- package/dist/ui/menu/anchor.d.ts +0 -18
- package/dist/ui/menu/anchor.d.ts.map +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Match as M, Option, Schema as S } from 'effect';
|
|
2
|
+
import { html } from '../../html';
|
|
3
|
+
import { m } from '../../message';
|
|
4
|
+
import { evo } from '../../struct';
|
|
5
|
+
// MODEL
|
|
6
|
+
/** Schema for the switch component's state, tracking the toggle's checked status. */
|
|
7
|
+
export const Model = S.Struct({
|
|
8
|
+
id: S.String,
|
|
9
|
+
isChecked: S.Boolean,
|
|
10
|
+
});
|
|
11
|
+
// MESSAGE
|
|
12
|
+
/** Sent when the user toggles the switch via click or Space key. */
|
|
13
|
+
export const Toggled = m('Toggled');
|
|
14
|
+
/** Placeholder message used when no action is needed. */
|
|
15
|
+
export const NoOp = m('NoOp');
|
|
16
|
+
/** Union of all messages the switch component can produce. */
|
|
17
|
+
export const Message = S.Union(Toggled, NoOp);
|
|
18
|
+
/** Creates an initial switch model from a config. Defaults to unchecked. */
|
|
19
|
+
export const init = (config) => ({
|
|
20
|
+
id: config.id,
|
|
21
|
+
isChecked: config.isChecked ?? false,
|
|
22
|
+
});
|
|
23
|
+
// UPDATE
|
|
24
|
+
/** Processes a switch message and returns the next model and commands. */
|
|
25
|
+
export const update = (model, message) => M.value(message).pipe(M.withReturnType(), M.tagsExhaustive({
|
|
26
|
+
Toggled: () => [evo(model, { isChecked: isChecked => !isChecked }), []],
|
|
27
|
+
NoOp: () => [model, []],
|
|
28
|
+
}));
|
|
29
|
+
const labelId = (id) => `${id}-label`;
|
|
30
|
+
const descriptionId = (id) => `${id}-description`;
|
|
31
|
+
/** Renders an accessible switch toggle by building ARIA attribute groups and delegating layout to the consumer's `toView` callback. */
|
|
32
|
+
export const view = (config) => {
|
|
33
|
+
const { AriaChecked, AriaDescribedBy, AriaDisabled, AriaLabelledBy, DataAttribute, Id, Name, OnClick, OnKeyUpPreventDefault, Role, Tabindex, Type, Value, } = html();
|
|
34
|
+
const { model: { id, isChecked }, toMessage, isDisabled = false, name, value: formValue = 'on', } = config;
|
|
35
|
+
const handleKeyUp = (key) => M.value(key).pipe(M.when(' ', () => Option.some(toMessage(Toggled()))), M.orElse(() => Option.none()));
|
|
36
|
+
const checkedAttributes = isChecked ? [DataAttribute('checked', '')] : [];
|
|
37
|
+
const disabledAttributes = isDisabled
|
|
38
|
+
? [AriaDisabled(true), DataAttribute('disabled', '')]
|
|
39
|
+
: [];
|
|
40
|
+
const buttonAttributes = [
|
|
41
|
+
Role('switch'),
|
|
42
|
+
AriaChecked(isChecked),
|
|
43
|
+
AriaLabelledBy(labelId(id)),
|
|
44
|
+
AriaDescribedBy(descriptionId(id)),
|
|
45
|
+
Tabindex(0),
|
|
46
|
+
...checkedAttributes,
|
|
47
|
+
...disabledAttributes,
|
|
48
|
+
...(isDisabled
|
|
49
|
+
? []
|
|
50
|
+
: [OnClick(toMessage(Toggled())), OnKeyUpPreventDefault(handleKeyUp)]),
|
|
51
|
+
];
|
|
52
|
+
const labelAttributes = [
|
|
53
|
+
Id(labelId(id)),
|
|
54
|
+
...(isDisabled ? [] : [OnClick(toMessage(Toggled()))]),
|
|
55
|
+
];
|
|
56
|
+
const descriptionAttributes = [Id(descriptionId(id))];
|
|
57
|
+
const hiddenInputAttributes = name
|
|
58
|
+
? [Type('hidden'), Name(name), Value(isChecked ? formValue : '')]
|
|
59
|
+
: [];
|
|
60
|
+
return config.toView({
|
|
61
|
+
button: buttonAttributes,
|
|
62
|
+
label: labelAttributes,
|
|
63
|
+
description: descriptionAttributes,
|
|
64
|
+
hiddenInput: hiddenInputAttributes,
|
|
65
|
+
});
|
|
66
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/ui/switch/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAE5D,YAAY,EACV,OAAO,EACP,IAAI,EACJ,UAAU,EACV,UAAU,EACV,gBAAgB,GACjB,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { init, update, view, Model, Message } from './index';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Schema as S } from 'effect';
|
|
2
|
+
/** Schema for the transition animation state, tracking enter/leave phases for CSS transition coordination. */
|
|
3
|
+
export declare const TransitionState: S.Literal<["Idle", "EnterStart", "EnterAnimating", "LeaveStart", "LeaveAnimating"]>;
|
|
4
|
+
export type TransitionState = typeof TransitionState.Type;
|
|
5
|
+
//# sourceMappingURL=transition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transition.d.ts","sourceRoot":"","sources":["../../src/ui/transition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAEpC,8GAA8G;AAC9G,eAAO,MAAM,eAAe,qFAM3B,CAAA;AACD,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,IAAI,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Elm-inspired UI framework powered by Effect",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -79,6 +79,14 @@
|
|
|
79
79
|
"types": "./dist/ui/menu/public.d.ts",
|
|
80
80
|
"import": "./dist/ui/menu/public.js"
|
|
81
81
|
},
|
|
82
|
+
"./ui/popover": {
|
|
83
|
+
"types": "./dist/ui/popover/public.d.ts",
|
|
84
|
+
"import": "./dist/ui/popover/public.js"
|
|
85
|
+
},
|
|
86
|
+
"./ui/switch": {
|
|
87
|
+
"types": "./dist/ui/switch/public.d.ts",
|
|
88
|
+
"import": "./dist/ui/switch/public.js"
|
|
89
|
+
},
|
|
82
90
|
"./ui/tabs": {
|
|
83
91
|
"types": "./dist/ui/tabs/public.d.ts",
|
|
84
92
|
"import": "./dist/ui/tabs/public.js"
|
package/dist/ui/menu/anchor.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Placement } from '@floating-ui/dom';
|
|
2
|
-
/** Static configuration for anchor-based positioning of menu items relative to the button. */
|
|
3
|
-
export type AnchorConfig = Readonly<{
|
|
4
|
-
placement?: Placement;
|
|
5
|
-
gap?: number;
|
|
6
|
-
offset?: number;
|
|
7
|
-
padding?: number;
|
|
8
|
-
portal?: boolean;
|
|
9
|
-
}>;
|
|
10
|
-
/** Returns insert/destroy hook callbacks that position the menu items container relative to its button using Floating UI. */
|
|
11
|
-
export declare const anchorHooks: (config: {
|
|
12
|
-
buttonId: string;
|
|
13
|
-
anchor: AnchorConfig;
|
|
14
|
-
}) => Readonly<{
|
|
15
|
-
onInsert: (items: Element) => void;
|
|
16
|
-
onDestroy: (items: Element) => void;
|
|
17
|
-
}>;
|
|
18
|
-
//# sourceMappingURL=anchor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"anchor.d.ts","sourceRoot":"","sources":["../../../src/ui/menu/anchor.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEjD,8FAA8F;AAC9F,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC;IAClC,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAC,CAAA;AAmBF,6HAA6H;AAC7H,eAAO,MAAM,WAAW,GAAI,QAAQ;IAClC,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,YAAY,CAAA;CACrB,KAAG,QAAQ,CAAC;IACX,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAClC,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACpC,CAsEC,CAAA"}
|