@cobwds/cob-button 1.19.4 → 1.23.1
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/dist/cob-button.d.ts +338 -0
- package/dist/cob-button.figma.d.ts +1 -0
- package/dist/cob-button.js +249 -1133
- package/dist/cob-button.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/package.json +5 -4
- package/dist/cob-icon.library-BR0WCz7Q-CwcFQs-u.js +0 -710
- package/dist/cob-icon.library-BR0WCz7Q-CwcFQs-u.js.map +0 -1
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { CobFormControlElement } from "@cobwds/internals";
|
|
2
|
+
import "@cobwds/cob-icon";
|
|
3
|
+
/**
|
|
4
|
+
* A button for actions like saving, submitting, or navigating. Form-associated with full keyboard support.
|
|
5
|
+
*
|
|
6
|
+
* Use `filled` for primary actions (one per section), `outline` for secondary, `ghost` for tertiary,
|
|
7
|
+
* `text` for inline. Set `href` to render as a navigation link.
|
|
8
|
+
*
|
|
9
|
+
* ARIA belongs on the component's props, not on the `<cob-button>` host. The host has no role,
|
|
10
|
+
* so attributes placed there are not mapped into the accessibility tree and never reach the
|
|
11
|
+
* internal `<button>`. For a disclosure trigger use `ariaExpanded` together with `ariaControls`.
|
|
12
|
+
*
|
|
13
|
+
* @summary Button for actions and CTAs with variants, sizes, and icon support.
|
|
14
|
+
* @element cob-button
|
|
15
|
+
*
|
|
16
|
+
* @slot - Button label text. Use as fallback when `label` prop is not provided.
|
|
17
|
+
* @slot prefix-icon - Icon before label. Not shown for `text` variant.
|
|
18
|
+
* @slot suffix-icon - Icon after label. Not shown for `text` variant.
|
|
19
|
+
* @slot circle-icon - Icon for circle mode. Overrides `icon` prop.
|
|
20
|
+
*
|
|
21
|
+
* @cssprop [--cob-button-color] - Text color of the button label.
|
|
22
|
+
* @cssprop [--cob-button-color--hover] - Text color when hovered.
|
|
23
|
+
* @cssprop [--cob-button-color--active] - Text color when active/pressed.
|
|
24
|
+
* @cssprop [--cob-button-background-color] - Background color of the button.
|
|
25
|
+
* @cssprop [--cob-button-background-color--hover] - Background color when hovered.
|
|
26
|
+
* @cssprop [--cob-button-background-color--active] - Background color when active/pressed.
|
|
27
|
+
* @cssprop [--cob-button-border-color] - Border color of the button.
|
|
28
|
+
* @cssprop [--cob-button-border-color--hover] - Border color when hovered.
|
|
29
|
+
* @cssprop [--cob-button-border-color--active] - Border color when active/pressed.
|
|
30
|
+
*
|
|
31
|
+
* @fires {Event} cob-click - Fired when the button is clicked (mouse or keyboard). Not fired when disabled.
|
|
32
|
+
* @fires {Event} cob-focus - Fired when the button receives focus.
|
|
33
|
+
* @fires {Event} cob-blur - Fired when the button loses focus.
|
|
34
|
+
*
|
|
35
|
+
* @usage
|
|
36
|
+
* - Use for the most important actions you want users to take, such as "Download", "Sign up", or "Log out".
|
|
37
|
+
* - Use `variant="fill"` for the primary action on the page. There should be only one primary action per page.
|
|
38
|
+
* - Use `variant="outline"` for secondary actions, placed next to the primary Fill button.
|
|
39
|
+
* - Use `variant="ghost"` buttons for additional actions beyond primary and secondary.
|
|
40
|
+
* - Use `variant="text"` buttons when an action needs to appear within a text block. If clicking takes the user somewhere else, use a Link instead.
|
|
41
|
+
* - Always set the `type` attribute (`submit`, `button`, or `reset`). The default is `button`.
|
|
42
|
+
* - Use sentence case for button labels, only capitalizing the first word.
|
|
43
|
+
* - Place a `chevron_down icon` on the right for buttons that open a dropdown.
|
|
44
|
+
* - Don't use buttons for navigation. Use an `<a>` element or Text button for links that take users somewhere else.
|
|
45
|
+
* - Don't use icons in buttons without a text label. Very few icons are universally understood.
|
|
46
|
+
* - Don't create custom button styles (color, shape, size). Consistency helps users recognize buttons and predict behavior.
|
|
47
|
+
*
|
|
48
|
+
* @example Basic
|
|
49
|
+
* ```html
|
|
50
|
+
* <cob-button label="Button" variant="filled"></cob-button>
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example Variant Outline
|
|
54
|
+
* ```html
|
|
55
|
+
* <cob-button label="Button" variant="outline"></cob-button>
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example Variant Ghost
|
|
59
|
+
* ```html
|
|
60
|
+
* <cob-button label="Button" variant="ghost"></cob-button>
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example Variant Text
|
|
64
|
+
* ```html
|
|
65
|
+
* <cob-button label="Button" variant="text"></cob-button>
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example Prefix Icon
|
|
69
|
+
* ```html
|
|
70
|
+
* <cob-button label="Previous" prefixIcon="chevron_left"></cob-button>
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example Suffix Icon
|
|
74
|
+
* ```html
|
|
75
|
+
* <cob-button label="Next" suffixIcon="chevron_right"></cob-button>
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example Slotted Icons
|
|
79
|
+
* ```html
|
|
80
|
+
* <cob-button label="Slotted icons">
|
|
81
|
+
* <cob-icon color="#db117d" slot="prefix-icon" name="chevron_left"></cob-icon>
|
|
82
|
+
* <cob-icon color="#db117d" slot="suffix-icon" name="chevron_right"></cob-icon>
|
|
83
|
+
* </cob-button>
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @example Circle icon button
|
|
87
|
+
* ```html
|
|
88
|
+
* <cob-button circle icon="close" label="Close dialog"></cob-button>
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Size Small
|
|
92
|
+
* ```html
|
|
93
|
+
* <cob-button label="Small" size="sm"></cob-button>
|
|
94
|
+
* ```
|
|
95
|
+
* @example Size Large
|
|
96
|
+
* ```html
|
|
97
|
+
* <cob-button label="Large" size="lg"></cob-button>
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example Full width
|
|
101
|
+
* ```html
|
|
102
|
+
* <cob-button label="Full width" fullWidth></cob-button>
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @example Inverted
|
|
106
|
+
* ```html
|
|
107
|
+
* <cob-button label="Inverted" inverted></cob-button>
|
|
108
|
+
* ```
|
|
109
|
+
* @render Inverted
|
|
110
|
+
* ```html
|
|
111
|
+
* <div style="background: #1b1b1b; padding: 1rem;">
|
|
112
|
+
* <cob-button label="Inverted" inverted></cob-button>
|
|
113
|
+
* </div>
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @example Disabled
|
|
117
|
+
* ```html
|
|
118
|
+
* <cob-button label="Disabled" disabled></cob-button>
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @example Href
|
|
122
|
+
* ```html
|
|
123
|
+
* <cob-button label="Visit Boston.gov" href="https://www.boston.gov/" target="_blank" suffixIcon="open_in_new"></cob-button>
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @example Type
|
|
127
|
+
* ```html
|
|
128
|
+
* <cob-button type="submit" label="Save Changes" variant="filled"></cob-button>
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @example Disclosure trigger
|
|
132
|
+
* ```html
|
|
133
|
+
* <cob-button
|
|
134
|
+
* label="Here's how you know"
|
|
135
|
+
* ariaExpanded="false"
|
|
136
|
+
* ariaControls="trust-bar"
|
|
137
|
+
* ></cob-button>
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare class CobButton extends CobFormControlElement {
|
|
141
|
+
static styles: import("lit").CSSResult;
|
|
142
|
+
static shadowRootOptions: {
|
|
143
|
+
delegatesFocus: boolean;
|
|
144
|
+
clonable?: boolean;
|
|
145
|
+
customElementRegistry?: CustomElementRegistry;
|
|
146
|
+
mode: ShadowRootMode;
|
|
147
|
+
serializable?: boolean;
|
|
148
|
+
slotAssignment?: SlotAssignmentMode;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Unique identifier. Auto-generated if not provided.
|
|
152
|
+
*/
|
|
153
|
+
id: string;
|
|
154
|
+
/**
|
|
155
|
+
* Name for form submission.
|
|
156
|
+
*/
|
|
157
|
+
name: string;
|
|
158
|
+
/**
|
|
159
|
+
* Button height: `sm` (40px) for dense UIs, `md` (48px, default) for standard use, `lg` (56px) for prominent CTAs.
|
|
160
|
+
* @default "md"
|
|
161
|
+
*/
|
|
162
|
+
size: "sm" | "md" | "lg";
|
|
163
|
+
/**
|
|
164
|
+
* Expands button to fill container width. Use for mobile layouts or stacked button groups.
|
|
165
|
+
* @default false
|
|
166
|
+
*/
|
|
167
|
+
fullWidth: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Visual style: `filled` for primary (one per section), `outline` for secondary, `ghost` for tertiary, `text` for inline actions. Avoid `text` for navigation.
|
|
170
|
+
* @default "filled"
|
|
171
|
+
*/
|
|
172
|
+
variant: "filled" | "outline" | "ghost" | "text";
|
|
173
|
+
/**
|
|
174
|
+
* Adjusts colors for dark backgrounds.
|
|
175
|
+
* @default false
|
|
176
|
+
*/
|
|
177
|
+
inverted: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Visible button text. Use sentence case, action-oriented text (e.g., "Save Draft"). In `circle` mode it is visually hidden but still exposed to assistive tech as the accessible name.
|
|
180
|
+
*/
|
|
181
|
+
label: string;
|
|
182
|
+
/**
|
|
183
|
+
* ID of controlled element (e.g., dropdown or modal). Sets `aria-controls`.
|
|
184
|
+
*
|
|
185
|
+
* Set this on `<cob-button>` rather than putting `aria-controls` on the host:
|
|
186
|
+
* the host has no role, so ARIA placed there is not mapped into the
|
|
187
|
+
* accessibility tree and never reaches the internal `<button>`.
|
|
188
|
+
*/
|
|
189
|
+
ariaControls: string;
|
|
190
|
+
/**
|
|
191
|
+
* Disclosure state for buttons that show/hide content. Sets `aria-expanded`
|
|
192
|
+
* on the internal `<button>`/`<a>`.
|
|
193
|
+
*
|
|
194
|
+
* Use `"false"` when the controlled content is collapsed and `"true"` when it
|
|
195
|
+
* is expanded, updating it every time the content toggles. Leave unset for
|
|
196
|
+
* buttons that are not disclosure triggers — an `aria-expanded` that never
|
|
197
|
+
* changes is worse than none. Pair with `ariaControls` pointing at the
|
|
198
|
+
* element being shown or hidden.
|
|
199
|
+
*
|
|
200
|
+
* Setting `aria-expanded` directly on the `<cob-button>` host does nothing:
|
|
201
|
+
* a custom element with no role does not map its ARIA attributes into the
|
|
202
|
+
* accessibility tree, and host ARIA does not cross into the shadow root.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```html
|
|
206
|
+
* <cob-button
|
|
207
|
+
* label="Here's how you know"
|
|
208
|
+
* ariaExpanded="false"
|
|
209
|
+
* ariaControls="trust-bar"
|
|
210
|
+
* ></cob-button>
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
ariaExpanded: "true" | "false" | "";
|
|
214
|
+
/**
|
|
215
|
+
* Marks this button as the current item within a set of related controls — the current
|
|
216
|
+
* page of a pagination control, the current step of a wizard. Sets `aria-current` on the
|
|
217
|
+
* internal `<button>`/`<a>`.
|
|
218
|
+
*
|
|
219
|
+
* Use `"page"` inside a pagination landmark, `"step"` inside a step indicator, and
|
|
220
|
+
* `"true"` when no more specific token fits. Only one control in a set is ever current:
|
|
221
|
+
* leave the property unset on all the others rather than setting `"false"`, which the
|
|
222
|
+
* spec reads as "explicitly not current" and adds nothing.
|
|
223
|
+
*
|
|
224
|
+
* Setting `aria-current` directly on the `<cob-button>` host does nothing: a custom
|
|
225
|
+
* element with no role does not map its ARIA attributes into the accessibility tree,
|
|
226
|
+
* and host ARIA does not cross into the shadow root.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```html
|
|
230
|
+
* <cob-button label="3" ariaCurrent="page"></cob-button>
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
ariaCurrent: "page" | "step" | "location" | "date" | "time" | "true" | "false" | "";
|
|
234
|
+
/**
|
|
235
|
+
* Material Symbol icon before label. Not shown for `circle` mode.
|
|
236
|
+
*/
|
|
237
|
+
prefixIcon: string;
|
|
238
|
+
/**
|
|
239
|
+
* Material Symbol icon after label. Use `chevron_down` for dropdowns, `open_in_new` for external links. Not shown for `circle` mode.
|
|
240
|
+
*/
|
|
241
|
+
suffixIcon: string;
|
|
242
|
+
/**
|
|
243
|
+
* Renders circular icon-only button. Requires `icon` prop. `label` is rendered as visually-hidden text for the accessible name.
|
|
244
|
+
* @default false
|
|
245
|
+
*/
|
|
246
|
+
circle: boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Icon for circle mode. Required when `circle` is true. Scales with size (sm=24px, md=32px, lg=40px).
|
|
249
|
+
*/
|
|
250
|
+
icon: string;
|
|
251
|
+
/**
|
|
252
|
+
* Prevents interaction. Avoid disabling without explanation—show validation errors instead.
|
|
253
|
+
* @default false
|
|
254
|
+
*/
|
|
255
|
+
disabled: boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Form `id` to associate with. Use when button is outside the form element.
|
|
258
|
+
*/
|
|
259
|
+
form: string | null;
|
|
260
|
+
/**
|
|
261
|
+
* Value submitted with the form data, mirroring a native submit button.
|
|
262
|
+
*
|
|
263
|
+
* When `type="submit"` and both `name` and `value` are set, the entry
|
|
264
|
+
* `name=value` is included in the form's data only for submissions this
|
|
265
|
+
* button triggers. It is not included when the form is submitted another
|
|
266
|
+
* way (Enter in a text field, another button, `form.requestSubmit()`),
|
|
267
|
+
* and it is not readable from `new FormData(form)` outside a submission,
|
|
268
|
+
* matching native submitter semantics.
|
|
269
|
+
*
|
|
270
|
+
* A form-associated custom element cannot act as a native submitter, so
|
|
271
|
+
* the value is staged through `ElementInternals.setFormValue()` for the
|
|
272
|
+
* duration of the submission and cleared afterward.
|
|
273
|
+
*/
|
|
274
|
+
value: string;
|
|
275
|
+
/**
|
|
276
|
+
* ID(s) of element(s) describing this button. Sets `aria-describedby`.
|
|
277
|
+
*/
|
|
278
|
+
ariaDescribedBy: string;
|
|
279
|
+
/**
|
|
280
|
+
* Form behavior: `button` (default, no form action), `submit` (submits form), `reset` (resets form). Always set explicitly to avoid unintended submissions.
|
|
281
|
+
* @default "button"
|
|
282
|
+
*/
|
|
283
|
+
type: "submit" | "reset" | "button";
|
|
284
|
+
/**
|
|
285
|
+
* Click handler. Use instead of `@click` to ensure keyboard accessibility.
|
|
286
|
+
*
|
|
287
|
+
* @deprecated Listen for the `cob-click` event instead. `cob-click`
|
|
288
|
+
* bubbles, is composed, and fires for both mouse and keyboard activation
|
|
289
|
+
* but never while disabled. This property still works but is excluded
|
|
290
|
+
* from generated framework wrappers and goes away in 2.0.
|
|
291
|
+
*/
|
|
292
|
+
onClick: ((event: Event) => void) | null;
|
|
293
|
+
/**
|
|
294
|
+
* URL to navigate to. Renders as `<a>` tag. Omit for action buttons.
|
|
295
|
+
*/
|
|
296
|
+
href: string;
|
|
297
|
+
/**
|
|
298
|
+
* Link target: `_self` (same tab), `_blank` (new tab—add `suffixIcon="open_in_new"`), `_parent`, `_top`, or frame name.
|
|
299
|
+
* @default "_self"
|
|
300
|
+
*/
|
|
301
|
+
target: "_self" | "_blank" | "_parent" | "_top" | "framename";
|
|
302
|
+
private _hasPrefixSlot;
|
|
303
|
+
private _hasSuffixSlot;
|
|
304
|
+
private _hasCircleSlot;
|
|
305
|
+
/**
|
|
306
|
+
* Functions
|
|
307
|
+
* --------------------------------------------------------------------------
|
|
308
|
+
*
|
|
309
|
+
* Form association, ElementInternals, and id generation are provided by
|
|
310
|
+
* CobFormControlElement (@cobwds/internals). super.connectedCallback() assigns
|
|
311
|
+
* an id when one is not provided (prefix = the element's localName).
|
|
312
|
+
*/
|
|
313
|
+
private _onPrefixSlotChange;
|
|
314
|
+
private _onSuffixSlotChange;
|
|
315
|
+
private _onCircleSlotChange;
|
|
316
|
+
private _manageFormAction;
|
|
317
|
+
/**
|
|
318
|
+
* Event Handlers
|
|
319
|
+
* --------------------------------------------------------------------------
|
|
320
|
+
*/
|
|
321
|
+
private _handleFocus;
|
|
322
|
+
private _handleBlur;
|
|
323
|
+
private _handleClick;
|
|
324
|
+
private _handleKeydown;
|
|
325
|
+
private _handleKeyup;
|
|
326
|
+
/**
|
|
327
|
+
* Handles inline onclick attributes for keyboard activation.
|
|
328
|
+
*
|
|
329
|
+
* Native clicks execute inline onclick attributes automatically, but
|
|
330
|
+
* keyboard activation of the custom element does not trigger that native
|
|
331
|
+
* behavior. Dispatching a synthetic click lets the browser's own inline
|
|
332
|
+
* event handler mechanism execute any onclick attribute safely without
|
|
333
|
+
* eval() or new Function().
|
|
334
|
+
*/
|
|
335
|
+
private _handleAnyAttributeFunction;
|
|
336
|
+
focus(options?: FocusOptions): void;
|
|
337
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
338
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|