@pontive/pontkit-core 1.17.2 → 1.18.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.
@@ -0,0 +1,98 @@
1
+ import { LitElement, PropertyValues } from 'lit';
2
+ import { PontRadioGroup } from './_radio-group';
3
+ import { RadioGroupItemProps, RadioGroupItemState } from './radio-group.defs';
4
+ /**
5
+ * The `<pont-radio-group-item>` component is a single option within a
6
+ * `<pont-radio-group>`. Its checked state is derived from the group's value.
7
+ *
8
+ * The host element itself is the radio: it carries `role="radio"` and its ARIA
9
+ * state (via `ElementInternals`), takes focus when it is the group's tab stop,
10
+ * and is checked on click and `Space`. It is form-associated, so it is
11
+ * labelable by `<label for>` and is disabled by a disabled `<fieldset>`.
12
+ *
13
+ * When the group has a `name`, the item also renders a visually hidden
14
+ * `<input type="radio">` mirroring its state, which submits the checked value
15
+ * with the owning form (as Base UI's radio does).
16
+ *
17
+ * @element pont-radio-group-item
18
+ */
19
+ export declare class PontRadioGroupItem extends LitElement implements RadioGroupItemProps {
20
+ static readonly formAssociated = true;
21
+ static readonly GROUP_TAG = "pont-radio-group";
22
+ /**
23
+ * The unique identifying value of the radio in a group.
24
+ */
25
+ value: string;
26
+ /**
27
+ * Whether the component should ignore user interaction.
28
+ */
29
+ disabled?: boolean;
30
+ /**
31
+ * Whether the user should be unable to select the radio button.
32
+ */
33
+ readonly?: boolean;
34
+ /**
35
+ * Whether the user must choose a value before submitting a form.
36
+ */
37
+ required?: boolean;
38
+ /**
39
+ * Whether the component is in an error state.
40
+ */
41
+ invalid?: boolean;
42
+ /**
43
+ * Whether the item is disabled by an ancestor (e.g. `<fieldset disabled>`).
44
+ */
45
+ private _formDisabled;
46
+ /**
47
+ * The group this item belongs to, resolved on connection.
48
+ */
49
+ private _group;
50
+ private readonly _internals;
51
+ protected createRenderRoot(): this;
52
+ /**
53
+ * The nearest `<pont-radio-group>` ancestor, if any.
54
+ */
55
+ get group(): PontRadioGroup | null;
56
+ /**
57
+ * Whether this item's value is the group's value.
58
+ */
59
+ get checked(): boolean;
60
+ get isDisabled(): boolean;
61
+ get isReadonly(): boolean;
62
+ get isRequired(): boolean;
63
+ get isInvalid(): boolean;
64
+ get state(): RadioGroupItemState;
65
+ connectedCallback(): void;
66
+ disconnectedCallback(): void;
67
+ protected updated(changed: PropertyValues): void;
68
+ formDisabledCallback(disabled: boolean): void;
69
+ /**
70
+ * Writes the ARIA state and tab stop of the host, which is the element
71
+ * exposed as the radio.
72
+ */
73
+ private _syncHostState;
74
+ /**
75
+ * Handles clicks on the host, including clicks forwarded from an associated
76
+ * `<label>` and those synthesised by the keyboard handlers.
77
+ */
78
+ private _handleClick;
79
+ /**
80
+ * Mirrors native radio behaviour: `Space` suppresses page scroll on keydown
81
+ * and checks the item on keyup. Arrow keys are handled by the group.
82
+ */
83
+ private _handleKeydown;
84
+ private _handleKeyup;
85
+ /**
86
+ * Renders the indicator only while the item is checked, as Base UI does by
87
+ * default (i.e. without `keepMounted`).
88
+ */
89
+ private _renderIndicator;
90
+ /**
91
+ * Renders a visually hidden `<input type="radio">` when the group has a
92
+ * `name`, kept in sync with the item so its value is included in form
93
+ * submissions. It is never focused or clicked directly: focus is moved to the
94
+ * host.
95
+ */
96
+ private _renderInput;
97
+ render(): import('lit-html').TemplateResult<1>;
98
+ }
@@ -0,0 +1,184 @@
1
+ import { LitElement, PropertyValues } from 'lit';
2
+ import { PontRadioGroupItem } from './_radio-group-item';
3
+ import { RadioGroupProps } from './radio-group.defs';
4
+ /**
5
+ * The `<pont-radio-group>` component is a set of checkable buttons, known as
6
+ * radio buttons, where no more than one of the buttons can be checked at a
7
+ * time. It holds the selected value; each `<pont-radio-group-item>` inside it
8
+ * is one option.
9
+ *
10
+ * The host element itself is the group: it carries `role="radiogroup"` and its
11
+ * ARIA state (via `ElementInternals`). Arrow keys move focus between enabled
12
+ * items and check the focused one, and only one item is a tab stop: the checked
13
+ * item, or the first enabled item when nothing is checked. It is
14
+ * form-associated, so it validates `required` against its owning form,
15
+ * restores `defaultValue` on form reset, and is disabled by a disabled
16
+ * `<fieldset>`. The value itself is submitted by the hidden input each item
17
+ * renders when `name` is set.
18
+ *
19
+ * The group renders a `[data-pont-radio-group]` container and moves its
20
+ * children (the items, and anything around them) into it, including children
21
+ * appended after the first render.
22
+ *
23
+ * @element pont-radio-group
24
+ *
25
+ * @event pont-radio-group:value-change - Fired when the user checks an item.
26
+ * Detail: `{ value: string }`
27
+ */
28
+ export declare class PontRadioGroup extends LitElement implements RadioGroupProps {
29
+ static readonly formAssociated = true;
30
+ static readonly VALUE_CHANGE_EVENT = "pont-radio-group:value-change";
31
+ static readonly ITEM_TAG = "pont-radio-group-item";
32
+ /**
33
+ * Identifies the field when a form is submitted.
34
+ */
35
+ name?: string;
36
+ /**
37
+ * The uncontrolled value of the radio button that should be initially
38
+ * selected.
39
+ * To render a controlled radio group, use the `value` prop instead.
40
+ */
41
+ defaultValue?: string;
42
+ /**
43
+ * The controlled value of the radio item that should be currently selected.
44
+ * To render an uncontrolled radio group, use the `defaultValue` prop instead.
45
+ */
46
+ value?: string | null;
47
+ /**
48
+ * Callback fired when the value changes.
49
+ */
50
+ onValueChange?: (value: string) => void;
51
+ /**
52
+ * Whether the component should ignore user interaction.
53
+ */
54
+ disabled?: boolean;
55
+ /**
56
+ * Whether the user should be unable to select a different radio button in the
57
+ * group.
58
+ */
59
+ readonly?: boolean;
60
+ /**
61
+ * Whether the user must choose a value before submitting a form.
62
+ */
63
+ required?: boolean;
64
+ /**
65
+ * Whether the component should indicate an error state.
66
+ */
67
+ invalid?: boolean;
68
+ /**
69
+ * The internal value, used when the group is uncontrolled.
70
+ */
71
+ private _value;
72
+ /**
73
+ * Whether the group is disabled by an ancestor (e.g. `<fieldset disabled>`).
74
+ */
75
+ private _formDisabled;
76
+ /**
77
+ * Gates whether `defaultValue` or `_value` is authoritative while
78
+ * uncontrolled. True once the user has checked an item.
79
+ */
80
+ private _dirty;
81
+ private readonly _internals;
82
+ /**
83
+ * Moves children appended directly to the host after the first render into
84
+ * the container.
85
+ */
86
+ private readonly _childObserver;
87
+ /**
88
+ * The marker comment Lit renders the group's template after.
89
+ */
90
+ private _renderMarker;
91
+ protected createRenderRoot(): this;
92
+ /**
93
+ * Returns `true` if the group is in controlled mode, determined by whether
94
+ * the `value` prop was explicitly provided.
95
+ */
96
+ get isControlled(): boolean;
97
+ /**
98
+ * The value of the checked item, from `value` if controlled, otherwise from
99
+ * internal state. `null` when no item is checked.
100
+ */
101
+ get currentValue(): string | null;
102
+ get isDisabled(): boolean;
103
+ get isInvalid(): boolean;
104
+ get isDirty(): boolean;
105
+ /**
106
+ * The items belonging to this group, in DOM order. Items of a nested group
107
+ * are excluded.
108
+ */
109
+ get items(): PontRadioGroupItem[];
110
+ /**
111
+ * The item currently in the tab order: the checked item if it is enabled,
112
+ * otherwise the first enabled item.
113
+ */
114
+ get tabStop(): PontRadioGroupItem | null;
115
+ /**
116
+ * The owning form, if any.
117
+ */
118
+ get form(): HTMLFormElement | null;
119
+ /**
120
+ * The validity state of the group within its owning form.
121
+ */
122
+ get validity(): ValidityState;
123
+ /**
124
+ * The container rendered by the group, which its children are moved into.
125
+ */
126
+ private get _container();
127
+ connectedCallback(): void;
128
+ disconnectedCallback(): void;
129
+ protected firstUpdated(): void;
130
+ protected willUpdate(changed: PropertyValues): void;
131
+ protected updated(): void;
132
+ formResetCallback(): void;
133
+ formDisabledCallback(disabled: boolean): void;
134
+ formStateRestoreCallback(state: string | null): void;
135
+ /**
136
+ * Moves focus to the item in the tab order.
137
+ */
138
+ focus(options?: FocusOptions): void;
139
+ /**
140
+ * Returns `true` if the group satisfies its constraints (i.e. it is not
141
+ * `required` with nothing checked), otherwise fires `invalid` and returns
142
+ * `false`.
143
+ */
144
+ checkValidity(): boolean;
145
+ /**
146
+ * Like `checkValidity()`, but also reports the problem to the user.
147
+ */
148
+ reportValidity(): boolean;
149
+ /**
150
+ * Checks the item with the given value, as if the user had chosen it. In
151
+ * uncontrolled mode, updates internal state directly. In controlled mode,
152
+ * leaves state to the parent, which must write back to `value`. Called by
153
+ * items; does nothing if the group is disabled or read-only, or the value is
154
+ * already checked.
155
+ */
156
+ select(value: string): void;
157
+ /**
158
+ * Moves the current children into the container, then keeps moving any
159
+ * appended later.
160
+ */
161
+ private _observeChildren;
162
+ /**
163
+ * Moves every child of the host into the container, in order, except the
164
+ * container itself and the marker comment Lit renders the group's template
165
+ * after (which must stay on the host for that template to keep updating).
166
+ */
167
+ private _moveChildrenIntoContainer;
168
+ /**
169
+ * Writes the ARIA state of the host, which is the element exposed as the
170
+ * group.
171
+ */
172
+ private _syncHostState;
173
+ /**
174
+ * Writes the restorable state and validity of the group to its owning form.
175
+ * The group submits no value of its own; its items' hidden inputs do.
176
+ */
177
+ private _syncFormState;
178
+ /**
179
+ * Moves focus between enabled items with the arrow keys, wrapping at either
180
+ * end, and checks the newly focused item (unless the group is read-only).
181
+ */
182
+ private _handleKeydown;
183
+ render(): import('lit-html').TemplateResult<1>;
184
+ }
@@ -1,19 +1,13 @@
1
- import { BaseElement } from '../../../helpers';
2
- import { PropertyValues } from 'lit';
3
- import { RadioGroupItem } from './radio-group-item';
4
- declare class RadioGroup extends BaseElement {
5
- defaultValue: string;
6
- get _containerElement(): HTMLDivElement | null;
7
- connectedCallback(): void;
8
- private _handleRadioSelected;
9
- protected createRenderRoot(): HTMLElement | DocumentFragment;
10
- protected firstUpdated(_changedProperties: PropertyValues): void;
11
- render(): import('lit-html').TemplateResult<1>;
12
- }
13
- export { RadioGroup, RadioGroupItem };
1
+ import { PontRadioGroup } from './_radio-group';
2
+ import { PontRadioGroupItem } from './_radio-group-item';
3
+ export { PontRadioGroup, PontRadioGroupItem };
4
+ /**
5
+ * A set of checkable buttons, known as radio buttons, where no more than one
6
+ * of the buttons can be checked at a time.
7
+ */
14
8
  declare global {
15
9
  interface HTMLElementTagNameMap {
16
- 'pont-radio-group': RadioGroup;
17
- 'pont-radio-group-item': RadioGroupItem;
10
+ "pont-radio-group": PontRadioGroup;
11
+ "pont-radio-group-item": PontRadioGroupItem;
18
12
  }
19
13
  }
@@ -0,0 +1,18 @@
1
+ export type RadioGroupItemState = "checked" | "unchecked";
2
+ export interface RadioGroupProps {
3
+ name?: string;
4
+ defaultValue?: string;
5
+ value?: string | null;
6
+ onValueChange?: (value: string) => void;
7
+ disabled?: boolean;
8
+ readonly?: boolean;
9
+ required?: boolean;
10
+ invalid?: boolean;
11
+ }
12
+ export interface RadioGroupItemProps {
13
+ value: string;
14
+ disabled?: boolean;
15
+ readonly?: boolean;
16
+ required?: boolean;
17
+ invalid?: boolean;
18
+ }
@@ -1,4 +1,13 @@
1
- import { Meta, StoryFn } from '@storybook/web-components-vite';
2
- declare const _default: Meta;
3
- export default _default;
4
- export declare const RadioGroup: StoryFn;
1
+ import { Meta, StoryObj } from '@storybook/web-components-vite';
2
+ declare const meta: Meta;
3
+ export default meta;
4
+ type Story = StoryObj;
5
+ export declare const Demo: Story;
6
+ export declare const Description: Story;
7
+ export declare const ChoiceCard: Story;
8
+ export declare const Fieldset: Story;
9
+ export declare const Disabled: Story;
10
+ export declare const Invalid: Story;
11
+ export declare const States: Story;
12
+ export declare const Controlled: Story;
13
+ export declare const Form: Story;