@mixtint/primer-view-components 0.72.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/LICENSE.txt +21 -0
- package/README.md +30 -0
- package/app/assets/images/loading_indicator.svg +1 -0
- package/app/assets/javascripts/components/primer/alpha/action_bar_element.d.ts +17 -0
- package/app/assets/javascripts/components/primer/alpha/action_list.d.ts +16 -0
- package/app/assets/javascripts/components/primer/alpha/action_menu/action_menu_element.d.ts +49 -0
- package/app/assets/javascripts/components/primer/alpha/action_menu/action_menu_focus_zone_stack.d.ts +17 -0
- package/app/assets/javascripts/components/primer/alpha/dropdown/menu.d.ts +1 -0
- package/app/assets/javascripts/components/primer/alpha/dropdown.d.ts +1 -0
- package/app/assets/javascripts/components/primer/alpha/modal_dialog.d.ts +18 -0
- package/app/assets/javascripts/components/primer/alpha/segmented_control.d.ts +12 -0
- package/app/assets/javascripts/components/primer/alpha/select_panel_element.d.ts +65 -0
- package/app/assets/javascripts/components/primer/alpha/tab_container.d.ts +1 -0
- package/app/assets/javascripts/components/primer/alpha/toggle_switch.d.ts +34 -0
- package/app/assets/javascripts/components/primer/alpha/tool_tip.d.ts +27 -0
- package/app/assets/javascripts/components/primer/alpha/tree_view/tree_view.d.ts +42 -0
- package/app/assets/javascripts/components/primer/alpha/tree_view/tree_view_icon_pair_element.d.ts +15 -0
- package/app/assets/javascripts/components/primer/alpha/tree_view/tree_view_include_fragment_element.d.ts +9 -0
- package/app/assets/javascripts/components/primer/alpha/tree_view/tree_view_roving_tab_index.d.ts +3 -0
- package/app/assets/javascripts/components/primer/alpha/tree_view/tree_view_sub_tree_node_element.d.ts +45 -0
- package/app/assets/javascripts/components/primer/alpha/x_banner.d.ts +18 -0
- package/app/assets/javascripts/components/primer/anchored_position.d.ts +27 -0
- package/app/assets/javascripts/components/primer/beta/auto_complete/auto_complete.d.ts +1 -0
- package/app/assets/javascripts/components/primer/beta/clipboard_copy.d.ts +1 -0
- package/app/assets/javascripts/components/primer/beta/details_toggle_element.d.ts +40 -0
- package/app/assets/javascripts/components/primer/beta/nav_list.d.ts +20 -0
- package/app/assets/javascripts/components/primer/beta/nav_list_group_element.d.ts +19 -0
- package/app/assets/javascripts/components/primer/beta/relative_time.d.ts +1 -0
- package/app/assets/javascripts/components/primer/dialog_helper.d.ts +15 -0
- package/app/assets/javascripts/components/primer/focus_group.d.ts +19 -0
- package/app/assets/javascripts/components/primer/open_project/border_box/collapsible_header.d.ts +11 -0
- package/app/assets/javascripts/components/primer/open_project/collapsible.d.ts +13 -0
- package/app/assets/javascripts/components/primer/open_project/collapsible_section.d.ts +10 -0
- package/app/assets/javascripts/components/primer/open_project/danger_dialog_form_helper.d.ts +14 -0
- package/app/assets/javascripts/components/primer/open_project/filterable_tree_view.d.ts +29 -0
- package/app/assets/javascripts/components/primer/open_project/page_header_element.d.ts +9 -0
- package/app/assets/javascripts/components/primer/open_project/sub_header_element.d.ts +17 -0
- package/app/assets/javascripts/components/primer/open_project/zen_mode_button.d.ts +18 -0
- package/app/assets/javascripts/components/primer/primer.d.ts +40 -0
- package/app/assets/javascripts/components/primer/scrollable_region.d.ts +13 -0
- package/app/assets/javascripts/components/primer/shared_events.d.ts +26 -0
- package/app/assets/javascripts/components/primer/utils.d.ts +1 -0
- package/app/assets/javascripts/lib/primer/forms/primer_multi_input.d.ts +10 -0
- package/app/assets/javascripts/lib/primer/forms/primer_text_field.d.ts +28 -0
- package/app/assets/javascripts/lib/primer/forms/toggle_switch_input.d.ts +5 -0
- package/app/assets/javascripts/primer_view_components.js +2 -0
- package/app/assets/javascripts/primer_view_components.js.map +1 -0
- package/app/assets/styles/primer_view_components.css +7336 -0
- package/app/assets/styles/primer_view_components.css.map +1 -0
- package/app/components/primer/alpha/action_bar.css +49 -0
- package/app/components/primer/alpha/action_bar.css.json +14 -0
- package/app/components/primer/alpha/action_bar_element.d.ts +17 -0
- package/app/components/primer/alpha/action_bar_element.js +170 -0
- package/app/components/primer/alpha/action_list.css +526 -0
- package/app/components/primer/alpha/action_list.css.json +117 -0
- package/app/components/primer/alpha/action_list.d.ts +16 -0
- package/app/components/primer/alpha/action_list.js +70 -0
- package/app/components/primer/alpha/action_menu/action_menu_element.d.ts +49 -0
- package/app/components/primer/alpha/action_menu/action_menu_element.js +591 -0
- package/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.d.ts +17 -0
- package/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.js +62 -0
- package/app/components/primer/alpha/auto_complete.css +131 -0
- package/app/components/primer/alpha/auto_complete.css.json +21 -0
- package/app/components/primer/alpha/banner.css +146 -0
- package/app/components/primer/alpha/banner.css.json +26 -0
- package/app/components/primer/alpha/button_marketing.css +183 -0
- package/app/components/primer/alpha/button_marketing.css.json +30 -0
- package/app/components/primer/alpha/dialog.css +377 -0
- package/app/components/primer/alpha/dialog.css.json +66 -0
- package/app/components/primer/alpha/dropdown/menu.d.ts +1 -0
- package/app/components/primer/alpha/dropdown/menu.js +1 -0
- package/app/components/primer/alpha/dropdown.css +296 -0
- package/app/components/primer/alpha/dropdown.css.json +40 -0
- package/app/components/primer/alpha/dropdown.d.ts +1 -0
- package/app/components/primer/alpha/dropdown.js +1 -0
- package/app/components/primer/alpha/layout.css +374 -0
- package/app/components/primer/alpha/layout.css.json +74 -0
- package/app/components/primer/alpha/menu.css +124 -0
- package/app/components/primer/alpha/menu.css.json +26 -0
- package/app/components/primer/alpha/modal_dialog.d.ts +18 -0
- package/app/components/primer/alpha/modal_dialog.js +187 -0
- package/app/components/primer/alpha/overlay.css +25 -0
- package/app/components/primer/alpha/overlay.css.json +12 -0
- package/app/components/primer/alpha/segmented_control.css +161 -0
- package/app/components/primer/alpha/segmented_control.css.json +31 -0
- package/app/components/primer/alpha/segmented_control.d.ts +12 -0
- package/app/components/primer/alpha/segmented_control.js +59 -0
- package/app/components/primer/alpha/select_panel.css +10 -0
- package/app/components/primer/alpha/select_panel.css.json +7 -0
- package/app/components/primer/alpha/select_panel_element.d.ts +65 -0
- package/app/components/primer/alpha/select_panel_element.js +988 -0
- package/app/components/primer/alpha/skeleton_box.css +36 -0
- package/app/components/primer/alpha/skeleton_box.css.json +6 -0
- package/app/components/primer/alpha/stack.css +266 -0
- package/app/components/primer/alpha/stack.css.json +94 -0
- package/app/components/primer/alpha/stack_item.css +27 -0
- package/app/components/primer/alpha/stack_item.css.json +12 -0
- package/app/components/primer/alpha/tab_container.d.ts +1 -0
- package/app/components/primer/alpha/tab_container.js +1 -0
- package/app/components/primer/alpha/tab_nav.css +112 -0
- package/app/components/primer/alpha/tab_nav.css.json +22 -0
- package/app/components/primer/alpha/text_field.css +838 -0
- package/app/components/primer/alpha/text_field.css.json +134 -0
- package/app/components/primer/alpha/toggle_switch.css +230 -0
- package/app/components/primer/alpha/toggle_switch.css.json +40 -0
- package/app/components/primer/alpha/toggle_switch.d.ts +34 -0
- package/app/components/primer/alpha/toggle_switch.js +179 -0
- package/app/components/primer/alpha/tool_tip.d.ts +27 -0
- package/app/components/primer/alpha/tool_tip.js +443 -0
- package/app/components/primer/alpha/tree_view/tree_view.d.ts +42 -0
- package/app/components/primer/alpha/tree_view/tree_view.js +391 -0
- package/app/components/primer/alpha/tree_view/tree_view_icon_pair_element.d.ts +15 -0
- package/app/components/primer/alpha/tree_view/tree_view_icon_pair_element.js +62 -0
- package/app/components/primer/alpha/tree_view/tree_view_include_fragment_element.d.ts +9 -0
- package/app/components/primer/alpha/tree_view/tree_view_include_fragment_element.js +28 -0
- package/app/components/primer/alpha/tree_view/tree_view_roving_tab_index.d.ts +3 -0
- package/app/components/primer/alpha/tree_view/tree_view_roving_tab_index.js +130 -0
- package/app/components/primer/alpha/tree_view/tree_view_sub_tree_node_element.d.ts +45 -0
- package/app/components/primer/alpha/tree_view/tree_view_sub_tree_node_element.js +429 -0
- package/app/components/primer/alpha/tree_view.css +396 -0
- package/app/components/primer/alpha/tree_view.css.json +52 -0
- package/app/components/primer/alpha/underline_nav.css +150 -0
- package/app/components/primer/alpha/underline_nav.css.json +26 -0
- package/app/components/primer/alpha/x_banner.d.ts +18 -0
- package/app/components/primer/alpha/x_banner.js +51 -0
- package/app/components/primer/anchored_position.d.ts +27 -0
- package/app/components/primer/anchored_position.js +159 -0
- package/app/components/primer/beta/auto_complete/auto_complete.d.ts +1 -0
- package/app/components/primer/beta/auto_complete/auto_complete.js +1 -0
- package/app/components/primer/beta/avatar.css +77 -0
- package/app/components/primer/beta/avatar.css.json +17 -0
- package/app/components/primer/beta/avatar_stack.css +145 -0
- package/app/components/primer/beta/avatar_stack.css.json +28 -0
- package/app/components/primer/beta/blankslate.css +168 -0
- package/app/components/primer/beta/blankslate.css.json +23 -0
- package/app/components/primer/beta/border_box.css +218 -0
- package/app/components/primer/beta/border_box.css.json +54 -0
- package/app/components/primer/beta/breadcrumbs.css +29 -0
- package/app/components/primer/beta/breadcrumbs.css.json +9 -0
- package/app/components/primer/beta/button.css +359 -0
- package/app/components/primer/beta/button.css.json +86 -0
- package/app/components/primer/beta/button_group.css +20 -0
- package/app/components/primer/beta/button_group.css.json +12 -0
- package/app/components/primer/beta/clipboard_copy.d.ts +1 -0
- package/app/components/primer/beta/clipboard_copy.js +58 -0
- package/app/components/primer/beta/counter.css +38 -0
- package/app/components/primer/beta/counter.css.json +10 -0
- package/app/components/primer/beta/details_toggle_element.d.ts +40 -0
- package/app/components/primer/beta/details_toggle_element.js +65 -0
- package/app/components/primer/beta/flash.css +152 -0
- package/app/components/primer/beta/flash.css.json +27 -0
- package/app/components/primer/beta/label.css +109 -0
- package/app/components/primer/beta/label.css.json +24 -0
- package/app/components/primer/beta/link.css +79 -0
- package/app/components/primer/beta/link.css.json +19 -0
- package/app/components/primer/beta/nav_list.d.ts +20 -0
- package/app/components/primer/beta/nav_list.js +192 -0
- package/app/components/primer/beta/nav_list_group_element.d.ts +19 -0
- package/app/components/primer/beta/nav_list_group_element.js +111 -0
- package/app/components/primer/beta/popover.css +215 -0
- package/app/components/primer/beta/popover.css.json +33 -0
- package/app/components/primer/beta/progress_bar.css +27 -0
- package/app/components/primer/beta/progress_bar.css.json +10 -0
- package/app/components/primer/beta/relative_time.d.ts +1 -0
- package/app/components/primer/beta/relative_time.js +1 -0
- package/app/components/primer/beta/state.css +59 -0
- package/app/components/primer/beta/state.css.json +13 -0
- package/app/components/primer/beta/subhead.css +64 -0
- package/app/components/primer/beta/subhead.css.json +14 -0
- package/app/components/primer/beta/timeline_item.css +106 -0
- package/app/components/primer/beta/timeline_item.css.json +16 -0
- package/app/components/primer/beta/truncate.css +30 -0
- package/app/components/primer/beta/truncate.css.json +12 -0
- package/app/components/primer/dialog_helper.d.ts +15 -0
- package/app/components/primer/dialog_helper.js +132 -0
- package/app/components/primer/focus_group.d.ts +19 -0
- package/app/components/primer/focus_group.js +163 -0
- package/app/components/primer/open_project/border_box/collapsible_header.css +21 -0
- package/app/components/primer/open_project/border_box/collapsible_header.css.json +11 -0
- package/app/components/primer/open_project/border_box/collapsible_header.d.ts +11 -0
- package/app/components/primer/open_project/border_box/collapsible_header.js +21 -0
- package/app/components/primer/open_project/border_grid.css +35 -0
- package/app/components/primer/open_project/border_grid.css.json +11 -0
- package/app/components/primer/open_project/collapsible.d.ts +13 -0
- package/app/components/primer/open_project/collapsible.js +67 -0
- package/app/components/primer/open_project/collapsible_section.css +5 -0
- package/app/components/primer/open_project/collapsible_section.css.json +6 -0
- package/app/components/primer/open_project/collapsible_section.d.ts +10 -0
- package/app/components/primer/open_project/collapsible_section.js +16 -0
- package/app/components/primer/open_project/danger_dialog_form_helper.d.ts +14 -0
- package/app/components/primer/open_project/danger_dialog_form_helper.js +54 -0
- package/app/components/primer/open_project/drag_handle.css +6 -0
- package/app/components/primer/open_project/drag_handle.css.json +6 -0
- package/app/components/primer/open_project/filterable_tree_view.d.ts +29 -0
- package/app/components/primer/open_project/filterable_tree_view.js +409 -0
- package/app/components/primer/open_project/input_group.css +22 -0
- package/app/components/primer/open_project/input_group.css.json +12 -0
- package/app/components/primer/open_project/page_header.css +87 -0
- package/app/components/primer/open_project/page_header.css.json +20 -0
- package/app/components/primer/open_project/page_header_element.d.ts +9 -0
- package/app/components/primer/open_project/page_header_element.js +23 -0
- package/app/components/primer/open_project/side_panel/section.css +27 -0
- package/app/components/primer/open_project/side_panel/section.css.json +11 -0
- package/app/components/primer/open_project/sub_header.css +80 -0
- package/app/components/primer/open_project/sub_header.css.json +17 -0
- package/app/components/primer/open_project/sub_header_element.d.ts +17 -0
- package/app/components/primer/open_project/sub_header_element.js +76 -0
- package/app/components/primer/open_project/zen_mode_button.d.ts +18 -0
- package/app/components/primer/open_project/zen_mode_button.js +64 -0
- package/app/components/primer/primer.d.ts +40 -0
- package/app/components/primer/primer.js +40 -0
- package/app/components/primer/scrollable_region.d.ts +13 -0
- package/app/components/primer/scrollable_region.js +52 -0
- package/app/components/primer/shared_events.d.ts +26 -0
- package/app/components/primer/shared_events.js +1 -0
- package/app/components/primer/truncate.css +23 -0
- package/app/components/primer/truncate.css.json +13 -0
- package/app/components/primer/utils.d.ts +1 -0
- package/app/components/primer/utils.js +16 -0
- package/app/lib/primer/forms/primer_multi_input.d.ts +10 -0
- package/app/lib/primer/forms/primer_multi_input.js +44 -0
- package/app/lib/primer/forms/primer_text_field.d.ts +28 -0
- package/app/lib/primer/forms/primer_text_field.js +119 -0
- package/app/lib/primer/forms/toggle_switch_input.d.ts +5 -0
- package/app/lib/primer/forms/toggle_switch_input.js +34 -0
- package/package.json +103 -0
- package/static/arguments.json +6472 -0
- package/static/audited_at.json +173 -0
- package/static/classes.json +781 -0
- package/static/constants.json +1972 -0
- package/static/form_previews.json +118 -0
- package/static/info_arch.json +21331 -0
- package/static/previews.json +9436 -0
- package/static/statuses.json +173 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "alpha/text_field",
|
|
3
|
+
"selectors": [
|
|
4
|
+
".FormControl",
|
|
5
|
+
".FormControl--fullWidth",
|
|
6
|
+
".FormControl-label",
|
|
7
|
+
".FormControl-caption",
|
|
8
|
+
".FormControl-caption a",
|
|
9
|
+
".FormControl-inlineValidation",
|
|
10
|
+
".FormControl-inlineValidation p",
|
|
11
|
+
".FormControl-inlineValidation--success",
|
|
12
|
+
".FormControl-inlineValidation--visual",
|
|
13
|
+
".FormControl-spacingWrapper",
|
|
14
|
+
".FormControl-horizontalGroup",
|
|
15
|
+
".FormControl-input",
|
|
16
|
+
".FormControl-select",
|
|
17
|
+
".FormControl-textarea",
|
|
18
|
+
"[disabled]:is(.FormControl-input,.FormControl-select,.FormControl-textarea)",
|
|
19
|
+
"[invalid='true']:is(.FormControl-input,.FormControl-select,.FormControl-textarea):not(:focus)",
|
|
20
|
+
"[invalid='false']:is(.FormControl-input,.FormControl-select,.FormControl-textarea):not(:focus)",
|
|
21
|
+
":is(.FormControl-input,.FormControl-select,.FormControl-textarea):not([type='checkbox'],[type='radio']):focus",
|
|
22
|
+
":is(.FormControl-input,.FormControl-select,.FormControl-textarea):not([type='checkbox'],[type='radio']):focus:not(:focus-visible)",
|
|
23
|
+
":is(.FormControl-input,.FormControl-select,.FormControl-textarea):not([type='checkbox'],[type='radio']):focus-visible",
|
|
24
|
+
"[disabled]:is(.FormControl-input,.FormControl-select,.FormControl-textarea)::placeholder",
|
|
25
|
+
"[readonly]:is(.FormControl-input,.FormControl-select,.FormControl-textarea)",
|
|
26
|
+
":is(.FormControl-input,.FormControl-select,.FormControl-textarea)::placeholder",
|
|
27
|
+
".FormControl-small:is(.FormControl-input,.FormControl-select,.FormControl-textarea)",
|
|
28
|
+
".FormControl-medium:is(.FormControl-input,.FormControl-select,.FormControl-textarea)",
|
|
29
|
+
".FormControl-large:is(.FormControl-input,.FormControl-select,.FormControl-textarea)",
|
|
30
|
+
".FormControl-inset:is(.FormControl-input,.FormControl-select,.FormControl-textarea)",
|
|
31
|
+
".FormControl-inset:is(.FormControl-input,.FormControl-select,.FormControl-textarea):focus-visible",
|
|
32
|
+
".FormControl-inset:is(.FormControl-input,.FormControl-select,.FormControl-textarea):focus",
|
|
33
|
+
".FormControl-monospace:is(.FormControl-input,.FormControl-select,.FormControl-textarea)",
|
|
34
|
+
".FormControl-error:is(.FormControl-input,.FormControl-select,.FormControl-textarea)",
|
|
35
|
+
".FormControl-success:is(.FormControl-input,.FormControl-select,.FormControl-textarea)",
|
|
36
|
+
".FormControl-warning:is(.FormControl-input,.FormControl-select,.FormControl-textarea)",
|
|
37
|
+
".FormControl-toggleSwitchInput",
|
|
38
|
+
".FormControl-input-wrap",
|
|
39
|
+
".FormControl-input-wrap.FormControl-input-width--auto",
|
|
40
|
+
".FormControl-input-wrap.FormControl-input-width--xsmall",
|
|
41
|
+
".FormControl-input-wrap.FormControl-input-width--small",
|
|
42
|
+
".FormControl-input-wrap.FormControl-input-width--medium",
|
|
43
|
+
".FormControl-input-wrap.FormControl-input-width--large",
|
|
44
|
+
".FormControl-input-wrap.FormControl-input-width--xlarge",
|
|
45
|
+
".FormControl-input-wrap.FormControl-input-width--xxlarge",
|
|
46
|
+
".FormControl-input-wrap .FormControl-input-leadingVisualWrap",
|
|
47
|
+
":is(.FormControl-input-wrap .FormControl-input-leadingVisualWrap) .FormControl-input-leadingVisual",
|
|
48
|
+
".FormControl-input-wrap .FormControl-input-trailingVisualWrap",
|
|
49
|
+
":is(.FormControl-input-wrap .FormControl-input-trailingVisualWrap):has(.FormControl-input-trailingVisualText)",
|
|
50
|
+
":is(.FormControl-input-wrap .FormControl-input-trailingVisualWrap):has(.FormControl-input-trailingVisualLabel)",
|
|
51
|
+
":is(.FormControl-input-wrap .FormControl-input-trailingVisualWrap) .FormControl-input-trailingVisualLabel",
|
|
52
|
+
".FormControl-input-wrap .FormControl-input-trailingAction",
|
|
53
|
+
":is(.FormControl-input-wrap .FormControl-input-trailingAction) svg",
|
|
54
|
+
"[disabled]:is(.FormControl-input-wrap .FormControl-input-trailingAction)",
|
|
55
|
+
":is(.FormControl-input-wrap .FormControl-input-trailingAction):hover",
|
|
56
|
+
":is(.FormControl-input-wrap .FormControl-input-trailingAction):active",
|
|
57
|
+
".FormControl-input-trailingAction--divider:is(.FormControl-input-wrap .FormControl-input-trailingAction)::before",
|
|
58
|
+
":is(:is(.FormControl-input-wrap .FormControl-input-trailingAction)::after)",
|
|
59
|
+
":is(.FormControl-input-wrap .FormControl-input-trailingAction)::after",
|
|
60
|
+
".FormControl-input-wrap.FormControl-input-wrap--leadingVisual .FormControl-input",
|
|
61
|
+
".FormControl-input-wrap.FormControl-input-wrap--trailingVisual .FormControl-input",
|
|
62
|
+
".FormControl-input-wrap.FormControl-input-wrap--trailingVisual:has(.FormControl-input-trailingVisualText) .FormControl-input",
|
|
63
|
+
".FormControl-input-wrap.FormControl-input-wrap--trailingVisual:has(.FormControl-input-trailingVisualLabel) .FormControl-input",
|
|
64
|
+
".FormControl-input-wrap.FormControl-input-wrap--trailingAction .FormControl-input",
|
|
65
|
+
".FormControl-input-wrap.FormControl-input-wrap--trailingAction.FormControl-input-wrap-trailingAction--divider .FormControl-input",
|
|
66
|
+
".FormControl-input-wrap.FormControl-input-wrap--small .FormControl-input-leadingVisualWrap",
|
|
67
|
+
".FormControl-input-wrap.FormControl-input-wrap--small .FormControl-input-trailingVisualWrap",
|
|
68
|
+
".FormControl-input-wrap.FormControl-input-wrap--small.FormControl-input-wrap--trailingAction .FormControl-input.FormControl-small",
|
|
69
|
+
".FormControl-input-wrap.FormControl-input-wrap--small.FormControl-input-wrap--trailingAction.FormControl-input-wrap-trailingAction--divider .FormControl-input.FormControl-small",
|
|
70
|
+
".FormControl-input-wrap.FormControl-input-wrap--small .FormControl-input-trailingAction",
|
|
71
|
+
":is(.FormControl-input-wrap.FormControl-input-wrap--small .FormControl-input-trailingAction)::before",
|
|
72
|
+
".FormControl-input-wrap.FormControl-input-wrap--large .FormControl-input-leadingVisualWrap",
|
|
73
|
+
".FormControl-input-wrap.FormControl-input-wrap--large .FormControl-input-trailingVisualWrap",
|
|
74
|
+
".FormControl-input-wrap.FormControl-input-wrap--large.FormControl-input-wrap--leadingVisual .FormControl-input.FormControl-large",
|
|
75
|
+
".FormControl-input-wrap.FormControl-input-wrap--large.FormControl-input-wrap--trailingVisual .FormControl-input",
|
|
76
|
+
".FormControl-input-wrap.FormControl-input-wrap--large.FormControl-input-wrap--trailingVisual:has(.FormControl-input-trailingVisualText) .FormControl-input",
|
|
77
|
+
".FormControl-input-wrap.FormControl-input-wrap--large.FormControl-input-wrap--trailingVisual:has(.FormControl-input-trailingVisualLabel) .FormControl-input",
|
|
78
|
+
".FormControl-input-wrap.FormControl-input-wrap--large.FormControl-input-wrap--trailingText .FormControl-input.FormControl-large",
|
|
79
|
+
".FormControl-input-wrap.FormControl-input-wrap--large.FormControl-input-wrap--trailingLabel .FormControl-input.FormControl-large",
|
|
80
|
+
".FormControl-input-wrap.FormControl-input-wrap--large.FormControl-input-wrap--trailingAction .FormControl-input.FormControl-large",
|
|
81
|
+
".FormControl-input-wrap.FormControl-input-wrap--large.FormControl-input-wrap--trailingAction.FormControl-input-wrap-trailingAction--divider .FormControl-input.FormControl-large",
|
|
82
|
+
".FormControl-input-wrap.FormControl-input-wrap--large .FormControl-input-trailingAction",
|
|
83
|
+
":is(.FormControl-input-wrap.FormControl-input-wrap--large .FormControl-input-trailingAction)::before",
|
|
84
|
+
".FormControl-select-wrap",
|
|
85
|
+
".FormControl-select-wrap.FormControl-input-width--auto",
|
|
86
|
+
".FormControl-select-wrap.FormControl-input-width--xsmall",
|
|
87
|
+
".FormControl-select-wrap.FormControl-input-width--small",
|
|
88
|
+
".FormControl-select-wrap.FormControl-input-width--medium",
|
|
89
|
+
".FormControl-select-wrap.FormControl-input-width--large",
|
|
90
|
+
".FormControl-select-wrap.FormControl-input-width--xlarge",
|
|
91
|
+
".FormControl-select-wrap.FormControl-input-width--xxlarge",
|
|
92
|
+
".FormControl-select-wrap::after",
|
|
93
|
+
".FormControl-select-wrap .FormControl-select",
|
|
94
|
+
".FormControl-select-wrap[data-multiple]::after",
|
|
95
|
+
".FormControl-select-wrap[data-multiple] .FormControl-select",
|
|
96
|
+
".FormControl-checkbox-wrap",
|
|
97
|
+
".FormControl-radio-wrap",
|
|
98
|
+
":is(.FormControl-checkbox-wrap,.FormControl-radio-wrap) .FormControl-checkbox-labelWrap",
|
|
99
|
+
":is(.FormControl-checkbox-wrap,.FormControl-radio-wrap) .FormControl-radio-labelWrap",
|
|
100
|
+
":is(.FormControl-checkbox-wrap,.FormControl-radio-wrap) .FormControl-label",
|
|
101
|
+
".FormControl-radio-group-wrap fieldset",
|
|
102
|
+
".FormControl-check-group-wrap fieldset",
|
|
103
|
+
".FormControl-checkbox",
|
|
104
|
+
".FormControl-checkbox[disabled]",
|
|
105
|
+
".FormControl-checkbox[invalid='true']:not(:focus)",
|
|
106
|
+
".FormControl-checkbox[invalid='false']:not(:focus)",
|
|
107
|
+
".FormControl-checkbox:not([type='checkbox'],[type='radio']):focus",
|
|
108
|
+
".FormControl-checkbox:not([type='checkbox'],[type='radio']):focus:not(:focus-visible)",
|
|
109
|
+
".FormControl-checkbox:not([type='checkbox'],[type='radio']):focus-visible",
|
|
110
|
+
".FormControl-checkbox::before",
|
|
111
|
+
":is(.FormControl-checkbox::after)",
|
|
112
|
+
":is(.FormControl-checkbox[disabled] ~ .FormControl-checkbox-labelWrap) .FormControl-label",
|
|
113
|
+
".FormControl-checkbox:checked",
|
|
114
|
+
".FormControl-checkbox:checked::before",
|
|
115
|
+
".FormControl-checkbox:checked:disabled",
|
|
116
|
+
".FormControl-checkbox:checked:disabled::before",
|
|
117
|
+
".FormControl-checkbox:focus-visible",
|
|
118
|
+
".FormControl-checkbox:indeterminate::before",
|
|
119
|
+
".FormControl-radio",
|
|
120
|
+
".FormControl-radio[disabled]",
|
|
121
|
+
".FormControl-radio[invalid='true']:not(:focus)",
|
|
122
|
+
".FormControl-radio[invalid='false']:not(:focus)",
|
|
123
|
+
".FormControl-radio:not([type='checkbox'],[type='radio']):focus",
|
|
124
|
+
".FormControl-radio:not([type='checkbox'],[type='radio']):focus:not(:focus-visible)",
|
|
125
|
+
".FormControl-radio:not([type='checkbox'],[type='radio']):focus-visible",
|
|
126
|
+
":is(.FormControl-radio::after)",
|
|
127
|
+
":is(.FormControl-radio[disabled] ~ .FormControl-radio-labelWrap) .FormControl-label",
|
|
128
|
+
".FormControl-radio:checked",
|
|
129
|
+
".FormControl-radio[disabled]:checked",
|
|
130
|
+
".FormControl-radio:checked:disabled",
|
|
131
|
+
":is(:is(.FormControl-radio[disabled]:checked,.FormControl-radio:checked:disabled) ~ .FormControl-radio-labelWrap) .FormControl-label",
|
|
132
|
+
".FormControl-radio:focus-visible"
|
|
133
|
+
]
|
|
134
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/* ToggleSwitch */
|
|
2
|
+
|
|
3
|
+
/* Catalyst in dotcom applies a display: block to all web component elements. This
|
|
4
|
+
** rule overrides it so the status label and toggle switch are laid out correctly. */
|
|
5
|
+
|
|
6
|
+
.ToggleSwitch.ToggleSwitch {
|
|
7
|
+
display: inline-flex;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.ToggleSwitch {
|
|
11
|
+
align-items: center;
|
|
12
|
+
display: inline-flex;
|
|
13
|
+
gap: var(--controlStack-medium-gap-condensed);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.ToggleSwitch--checked .ToggleSwitch-statusOn {
|
|
17
|
+
height: auto;
|
|
18
|
+
visibility: visible;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.ToggleSwitch--checked .ToggleSwitch-statusOff {
|
|
22
|
+
height: 0;
|
|
23
|
+
visibility: hidden;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.ToggleSwitch-track {
|
|
27
|
+
position: relative;
|
|
28
|
+
display: block;
|
|
29
|
+
width: var(--base-size-64);
|
|
30
|
+
height: var(--control-medium-size);
|
|
31
|
+
padding: 0;
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
-webkit-text-decoration: none;
|
|
34
|
+
text-decoration: none;
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
-webkit-user-select: none;
|
|
37
|
+
user-select: none;
|
|
38
|
+
background-color: var(--controlTrack-bgColor-rest);
|
|
39
|
+
border: var(--borderWidth-thin) solid var(--controlTrack-borderColor-rest);
|
|
40
|
+
border-radius: var(--borderRadius-medium);
|
|
41
|
+
transition-timing-function: cubic-bezier(0.5, 1, 0.89, 1);
|
|
42
|
+
transition-duration: 80ms;
|
|
43
|
+
transition-property: background-color, border-color;
|
|
44
|
+
appearance: none;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.ToggleSwitch-track:focus,.ToggleSwitch-track:focus-visible {
|
|
48
|
+
outline-offset: 1px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.ToggleSwitch-track:hover {
|
|
52
|
+
background-color: var(--controlTrack-bgColor-hover);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.ToggleSwitch-track:active {
|
|
56
|
+
background-color: var(--controlTrack-bgColor-active);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@media (pointer: coarse) {
|
|
60
|
+
:is(.ToggleSwitch-track::before) {
|
|
61
|
+
position: absolute;
|
|
62
|
+
top: 50%;
|
|
63
|
+
left: 50%;
|
|
64
|
+
width: 100%;
|
|
65
|
+
height: 100%;
|
|
66
|
+
min-height: 44px;
|
|
67
|
+
content: "";
|
|
68
|
+
transform: translateX(-50%) translateY(-50%);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@media (prefers-reduced-motion) {
|
|
73
|
+
|
|
74
|
+
.ToggleSwitch-track {
|
|
75
|
+
transition: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.ToggleSwitch-track * {
|
|
79
|
+
transition: none;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.ToggleSwitch-track[aria-pressed='true'][disabled] {
|
|
84
|
+
color: var(--control-checked-fgColor-disabled);
|
|
85
|
+
background-color: var(--controlTrack-bgColor-disabled);
|
|
86
|
+
border-color: transparent;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.ToggleSwitch-track[aria-pressed='true'] {
|
|
90
|
+
background-color: var(--control-checked-bgColor-rest);
|
|
91
|
+
border-color: var(--borderColor-transparent);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.ToggleSwitch-track[aria-pressed='true']:not([disabled]):hover {
|
|
95
|
+
background-color: var(--control-checked-bgColor-hover);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.ToggleSwitch-track[aria-pressed='true']:not([disabled]):active {
|
|
99
|
+
background-color: var(--control-checked-bgColor-active);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.ToggleSwitch-track[aria-pressed='true'] .ToggleSwitch-knob {
|
|
103
|
+
background-color: var(--controlKnob-bgColor-checked);
|
|
104
|
+
border-color: var(--controlKnob-borderColor-checked);
|
|
105
|
+
transform: translateX(100%);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.ToggleSwitch-track[aria-pressed='true'] .ToggleSwitch-lineIcon {
|
|
109
|
+
transform: translateX(0%);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.ToggleSwitch-track[aria-pressed='true'] .ToggleSwitch-circleIcon {
|
|
113
|
+
transform: translateX(100%);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.ToggleSwitch-track[disabled] {
|
|
117
|
+
cursor: not-allowed;
|
|
118
|
+
background-color: var(--controlTrack-bgColor-disabled);
|
|
119
|
+
border-color: transparent;
|
|
120
|
+
transition-property: none;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.ToggleSwitch-track[disabled] .ToggleSwitch-knob {
|
|
124
|
+
border-color: var(--borderColor-default);
|
|
125
|
+
box-shadow: none;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.ToggleSwitch-track[disabled] .ToggleSwitch-lineIcon {
|
|
129
|
+
color: var(--controlTrack-fgColor-disabled);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.ToggleSwitch-track[disabled] .ToggleSwitch-circleIcon {
|
|
133
|
+
color: var(--controlTrack-fgColor-disabled);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.ToggleSwitch-icons {
|
|
137
|
+
display: flex;
|
|
138
|
+
align-items: center;
|
|
139
|
+
width: 100%;
|
|
140
|
+
height: 100%;
|
|
141
|
+
overflow: hidden;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.ToggleSwitch-lineIcon {
|
|
145
|
+
/* stylelint-disable-next-line primer/typography */
|
|
146
|
+
line-height: 0;
|
|
147
|
+
color: var(--control-checked-fgColor-rest);
|
|
148
|
+
transition-duration: 80ms;
|
|
149
|
+
transition-property: transform;
|
|
150
|
+
transform: translateX(-100%);
|
|
151
|
+
flex: 1 0 50%;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.ToggleSwitch-circleIcon {
|
|
155
|
+
/* stylelint-disable-next-line primer/typography */
|
|
156
|
+
line-height: 0;
|
|
157
|
+
color: var(--controlTrack-fgColor-rest);
|
|
158
|
+
transition-duration: 80ms;
|
|
159
|
+
transition-property: transform;
|
|
160
|
+
transform: translateX(0);
|
|
161
|
+
flex: 1 0 50%;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.ToggleSwitch-knob {
|
|
165
|
+
position: absolute;
|
|
166
|
+
top: 0;
|
|
167
|
+
bottom: 0;
|
|
168
|
+
z-index: 1;
|
|
169
|
+
width: 50%;
|
|
170
|
+
background-color: var(--controlKnob-bgColor-rest);
|
|
171
|
+
border: var(--borderWidth-thin) solid var(--controlKnob-borderColor-rest);
|
|
172
|
+
border-radius: var(--borderRadius-medium);
|
|
173
|
+
box-shadow: var(--shadow-resting-medium), var(--button-default-shadow-inset);
|
|
174
|
+
transition-timing-function: cubic-bezier(0.5, 1, 0.89, 1);
|
|
175
|
+
transition-duration: 80ms;
|
|
176
|
+
transition-property: transform;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@media (prefers-reduced-motion) {
|
|
180
|
+
|
|
181
|
+
.ToggleSwitch-knob {
|
|
182
|
+
transition: none;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.ToggleSwitch-status {
|
|
187
|
+
position: relative;
|
|
188
|
+
font-size: var(--text-body-size-medium);
|
|
189
|
+
line-height: var(--text-title-lineHeight-large);
|
|
190
|
+
color: var(--fgColor-default);
|
|
191
|
+
text-align: right;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.ToggleSwitch-statusIcon {
|
|
195
|
+
display: flex;
|
|
196
|
+
width: var(--base-size-16);
|
|
197
|
+
/* stylelint-disable-next-line primer/spacing */
|
|
198
|
+
margin-top: 0.063rem;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.ToggleSwitch--small .ToggleSwitch-status {
|
|
202
|
+
font-size: var(--text-body-size-small);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.ToggleSwitch--small .ToggleSwitch-track {
|
|
206
|
+
width: var(--base-size-48);
|
|
207
|
+
height: var(--control-xsmall-size);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.ToggleSwitch--disabled .ToggleSwitch-status {
|
|
211
|
+
color: var(--fgColor-muted);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.ToggleSwitch-statusOn {
|
|
215
|
+
height: 0;
|
|
216
|
+
visibility: hidden;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.ToggleSwitch-statusOff {
|
|
220
|
+
height: auto;
|
|
221
|
+
visibility: visible;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.ToggleSwitch--statusAtEnd {
|
|
225
|
+
flex-direction: row-reverse;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.ToggleSwitch--statusAtEnd .ToggleSwitch-status {
|
|
229
|
+
text-align: left;
|
|
230
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "alpha/toggle_switch",
|
|
3
|
+
"selectors": [
|
|
4
|
+
".ToggleSwitch.ToggleSwitch",
|
|
5
|
+
".ToggleSwitch",
|
|
6
|
+
".ToggleSwitch--checked .ToggleSwitch-statusOn",
|
|
7
|
+
".ToggleSwitch--checked .ToggleSwitch-statusOff",
|
|
8
|
+
".ToggleSwitch-track",
|
|
9
|
+
".ToggleSwitch-track:focus",
|
|
10
|
+
".ToggleSwitch-track:focus-visible",
|
|
11
|
+
".ToggleSwitch-track:hover",
|
|
12
|
+
".ToggleSwitch-track:active",
|
|
13
|
+
":is(.ToggleSwitch-track::before)",
|
|
14
|
+
".ToggleSwitch-track *",
|
|
15
|
+
".ToggleSwitch-track[aria-pressed='true'][disabled]",
|
|
16
|
+
".ToggleSwitch-track[aria-pressed='true']",
|
|
17
|
+
".ToggleSwitch-track[aria-pressed='true']:not([disabled]):hover",
|
|
18
|
+
".ToggleSwitch-track[aria-pressed='true']:not([disabled]):active",
|
|
19
|
+
".ToggleSwitch-track[aria-pressed='true'] .ToggleSwitch-knob",
|
|
20
|
+
".ToggleSwitch-track[aria-pressed='true'] .ToggleSwitch-lineIcon",
|
|
21
|
+
".ToggleSwitch-track[aria-pressed='true'] .ToggleSwitch-circleIcon",
|
|
22
|
+
".ToggleSwitch-track[disabled]",
|
|
23
|
+
".ToggleSwitch-track[disabled] .ToggleSwitch-knob",
|
|
24
|
+
".ToggleSwitch-track[disabled] .ToggleSwitch-lineIcon",
|
|
25
|
+
".ToggleSwitch-track[disabled] .ToggleSwitch-circleIcon",
|
|
26
|
+
".ToggleSwitch-icons",
|
|
27
|
+
".ToggleSwitch-lineIcon",
|
|
28
|
+
".ToggleSwitch-circleIcon",
|
|
29
|
+
".ToggleSwitch-knob",
|
|
30
|
+
".ToggleSwitch-status",
|
|
31
|
+
".ToggleSwitch-statusIcon",
|
|
32
|
+
".ToggleSwitch--small .ToggleSwitch-status",
|
|
33
|
+
".ToggleSwitch--small .ToggleSwitch-track",
|
|
34
|
+
".ToggleSwitch--disabled .ToggleSwitch-status",
|
|
35
|
+
".ToggleSwitch-statusOn",
|
|
36
|
+
".ToggleSwitch-statusOff",
|
|
37
|
+
".ToggleSwitch--statusAtEnd",
|
|
38
|
+
".ToggleSwitch--statusAtEnd .ToggleSwitch-status"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
declare class ToggleSwitchElement extends HTMLElement {
|
|
2
|
+
switch: HTMLElement;
|
|
3
|
+
loadingSpinner: HTMLElement;
|
|
4
|
+
errorIcon: HTMLElement;
|
|
5
|
+
turbo: boolean;
|
|
6
|
+
private toggling;
|
|
7
|
+
get src(): string | null;
|
|
8
|
+
get csrf(): string | null;
|
|
9
|
+
get csrfField(): string;
|
|
10
|
+
isRemote(): boolean;
|
|
11
|
+
toggle(): Promise<void>;
|
|
12
|
+
turnOn(): void;
|
|
13
|
+
turnOff(): void;
|
|
14
|
+
isOn(): boolean;
|
|
15
|
+
isOff(): boolean;
|
|
16
|
+
isDisabled(): boolean;
|
|
17
|
+
disable(): void;
|
|
18
|
+
enable(): void;
|
|
19
|
+
private performToggle;
|
|
20
|
+
private setLoadingState;
|
|
21
|
+
private setSuccessState;
|
|
22
|
+
private setErrorState;
|
|
23
|
+
private setFinishedState;
|
|
24
|
+
private submitForm;
|
|
25
|
+
}
|
|
26
|
+
declare global {
|
|
27
|
+
interface Window {
|
|
28
|
+
ToggleSwitchElement: typeof ToggleSwitchElement;
|
|
29
|
+
Turbo: {
|
|
30
|
+
renderStreamMessage: (message: string) => void;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { controller, target, attr } from '@github/catalyst';
|
|
8
|
+
let ToggleSwitchElement = class ToggleSwitchElement extends HTMLElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.turbo = false;
|
|
12
|
+
this.toggling = false;
|
|
13
|
+
}
|
|
14
|
+
get src() {
|
|
15
|
+
const src = this.getAttribute('src');
|
|
16
|
+
if (!src)
|
|
17
|
+
return null;
|
|
18
|
+
const link = this.ownerDocument.createElement('a');
|
|
19
|
+
link.href = src;
|
|
20
|
+
return link.href;
|
|
21
|
+
}
|
|
22
|
+
get csrf() {
|
|
23
|
+
const csrfElement = this.querySelector('[data-csrf]');
|
|
24
|
+
return this.getAttribute('data-csrf') || (csrfElement instanceof HTMLInputElement && csrfElement.value) || null;
|
|
25
|
+
}
|
|
26
|
+
get csrfField() {
|
|
27
|
+
// the authenticity token is passed into the element and is not generated in js land
|
|
28
|
+
return this.getAttribute('csrf-field') || 'authenticity_token';
|
|
29
|
+
}
|
|
30
|
+
isRemote() {
|
|
31
|
+
return this.src != null;
|
|
32
|
+
}
|
|
33
|
+
async toggle() {
|
|
34
|
+
if (this.toggling)
|
|
35
|
+
return;
|
|
36
|
+
this.toggling = true;
|
|
37
|
+
if (this.isDisabled()) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!this.isRemote()) {
|
|
41
|
+
this.performToggle();
|
|
42
|
+
this.toggling = false;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// toggle immediately to tell screen readers the switch was clicked
|
|
46
|
+
this.performToggle();
|
|
47
|
+
this.setLoadingState();
|
|
48
|
+
try {
|
|
49
|
+
await this.submitForm();
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error instanceof Error) {
|
|
53
|
+
// because we toggle immediately when the switch is clicked, toggle back to the
|
|
54
|
+
// old state on failure
|
|
55
|
+
this.setErrorState(error.message || 'An error occurred, please try again.');
|
|
56
|
+
this.performToggle();
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
this.toggling = false;
|
|
62
|
+
}
|
|
63
|
+
this.setSuccessState();
|
|
64
|
+
}
|
|
65
|
+
turnOn() {
|
|
66
|
+
if (this.isDisabled()) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.switch.setAttribute('aria-pressed', 'true');
|
|
70
|
+
this.classList.add('ToggleSwitch--checked');
|
|
71
|
+
}
|
|
72
|
+
turnOff() {
|
|
73
|
+
if (this.isDisabled()) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.switch.setAttribute('aria-pressed', 'false');
|
|
77
|
+
this.classList.remove('ToggleSwitch--checked');
|
|
78
|
+
}
|
|
79
|
+
isOn() {
|
|
80
|
+
return this.switch.getAttribute('aria-pressed') === 'true';
|
|
81
|
+
}
|
|
82
|
+
isOff() {
|
|
83
|
+
return !this.isOn();
|
|
84
|
+
}
|
|
85
|
+
isDisabled() {
|
|
86
|
+
return this.switch.getAttribute('disabled') != null;
|
|
87
|
+
}
|
|
88
|
+
disable() {
|
|
89
|
+
this.switch.setAttribute('disabled', 'disabled');
|
|
90
|
+
}
|
|
91
|
+
enable() {
|
|
92
|
+
this.switch.removeAttribute('disabled');
|
|
93
|
+
}
|
|
94
|
+
performToggle() {
|
|
95
|
+
if (this.isOn()) {
|
|
96
|
+
this.turnOff();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this.turnOn();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
setLoadingState() {
|
|
103
|
+
this.errorIcon.setAttribute('hidden', 'hidden');
|
|
104
|
+
this.loadingSpinner.removeAttribute('hidden');
|
|
105
|
+
const event = new CustomEvent('toggleSwitchLoading', { bubbles: true });
|
|
106
|
+
this.dispatchEvent(event);
|
|
107
|
+
}
|
|
108
|
+
setSuccessState() {
|
|
109
|
+
const event = new CustomEvent('toggleSwitchSuccess', { bubbles: true });
|
|
110
|
+
this.dispatchEvent(event);
|
|
111
|
+
this.setFinishedState(false);
|
|
112
|
+
}
|
|
113
|
+
setErrorState(message) {
|
|
114
|
+
const event = new CustomEvent('toggleSwitchError', { bubbles: true, detail: message });
|
|
115
|
+
this.dispatchEvent(event);
|
|
116
|
+
this.setFinishedState(true);
|
|
117
|
+
}
|
|
118
|
+
setFinishedState(error) {
|
|
119
|
+
if (error) {
|
|
120
|
+
this.errorIcon.removeAttribute('hidden');
|
|
121
|
+
}
|
|
122
|
+
this.loadingSpinner.setAttribute('hidden', 'hidden');
|
|
123
|
+
}
|
|
124
|
+
async submitForm() {
|
|
125
|
+
const body = new FormData();
|
|
126
|
+
if (this.csrf) {
|
|
127
|
+
body.append(this.csrfField, this.csrf);
|
|
128
|
+
}
|
|
129
|
+
body.append('value', this.isOn() ? '1' : '0');
|
|
130
|
+
if (!this.src)
|
|
131
|
+
throw new Error('invalid src');
|
|
132
|
+
let response;
|
|
133
|
+
const requestHeaders = {
|
|
134
|
+
'Requested-With': 'XMLHttpRequest',
|
|
135
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
136
|
+
};
|
|
137
|
+
if (this.turbo) {
|
|
138
|
+
requestHeaders['Accept'] = 'text/vnd.turbo-stream.html';
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
response = await fetch(this.src, {
|
|
142
|
+
credentials: 'same-origin',
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: requestHeaders,
|
|
145
|
+
body,
|
|
146
|
+
});
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
throw new Error('A network error occurred, please try again.');
|
|
151
|
+
}
|
|
152
|
+
if (!response.ok) {
|
|
153
|
+
throw new Error(await response.text());
|
|
154
|
+
}
|
|
155
|
+
const contentType = response.headers.get('Content-Type');
|
|
156
|
+
if (window.Turbo && this.turbo && contentType?.startsWith('text/vnd.turbo-stream.html')) {
|
|
157
|
+
window.Turbo.renderStreamMessage(await response.text());
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
__decorate([
|
|
162
|
+
target
|
|
163
|
+
], ToggleSwitchElement.prototype, "switch", void 0);
|
|
164
|
+
__decorate([
|
|
165
|
+
target
|
|
166
|
+
], ToggleSwitchElement.prototype, "loadingSpinner", void 0);
|
|
167
|
+
__decorate([
|
|
168
|
+
target
|
|
169
|
+
], ToggleSwitchElement.prototype, "errorIcon", void 0);
|
|
170
|
+
__decorate([
|
|
171
|
+
attr
|
|
172
|
+
], ToggleSwitchElement.prototype, "turbo", void 0);
|
|
173
|
+
ToggleSwitchElement = __decorate([
|
|
174
|
+
controller
|
|
175
|
+
], ToggleSwitchElement);
|
|
176
|
+
if (!window.customElements.get('toggle-switch')) {
|
|
177
|
+
window.ToggleSwitchElement = ToggleSwitchElement;
|
|
178
|
+
window.customElements.define('toggle-switch', ToggleSwitchElement);
|
|
179
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import '@oddbird/popover-polyfill';
|
|
2
|
+
type Direction = 'n' | 's' | 'e' | 'w' | 'ne' | 'se' | 'nw' | 'sw';
|
|
3
|
+
declare class ToolTipElement extends HTMLElement {
|
|
4
|
+
#private;
|
|
5
|
+
styles(): string;
|
|
6
|
+
get showReason(): "focus" | "mouse";
|
|
7
|
+
get htmlFor(): string;
|
|
8
|
+
set htmlFor(value: string);
|
|
9
|
+
get type(): 'description' | 'label';
|
|
10
|
+
set type(value: 'description' | 'label');
|
|
11
|
+
get direction(): Direction;
|
|
12
|
+
set direction(value: Direction);
|
|
13
|
+
get control(): HTMLElement | null;
|
|
14
|
+
set hiddenFromView(value: true | false);
|
|
15
|
+
get hiddenFromView(): true | false;
|
|
16
|
+
connectedCallback(): void;
|
|
17
|
+
disconnectedCallback(): void;
|
|
18
|
+
handleEvent(event: Event): Promise<void>;
|
|
19
|
+
static observedAttributes: string[];
|
|
20
|
+
attributeChangedCallback(name: string): void;
|
|
21
|
+
}
|
|
22
|
+
declare global {
|
|
23
|
+
interface Window {
|
|
24
|
+
ToolTipElement: typeof ToolTipElement;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export {};
|