@nectary/components 2.9.0 → 2.11.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/accordion/index.d.ts +11 -0
- package/accordion/index.js +86 -0
- package/accordion/types.d.ts +21 -0
- package/accordion/types.js +1 -0
- package/accordion-item/index.d.ts +14 -0
- package/accordion-item/index.js +95 -0
- package/accordion-item/types.d.ts +36 -0
- package/accordion-item/types.js +1 -0
- package/accordion-item/utils.d.ts +2 -0
- package/accordion-item/utils.js +1 -0
- package/action-menu/index.d.ts +11 -0
- package/action-menu/index.js +195 -0
- package/action-menu/types.d.ts +13 -0
- package/action-menu/types.js +1 -0
- package/action-menu-option/index.d.ts +12 -0
- package/action-menu-option/index.js +82 -0
- package/action-menu-option/types.d.ts +23 -0
- package/action-menu-option/types.js +1 -0
- package/action-menu-option/utils.d.ts +2 -0
- package/action-menu-option/utils.js +3 -0
- package/alert/index.d.ts +14 -0
- package/alert/index.js +48 -0
- package/alert/types.d.ts +18 -0
- package/alert/types.js +1 -0
- package/alert/utils.d.ts +2 -0
- package/alert/utils.js +1 -0
- package/avatar/index.d.ts +11 -0
- package/avatar/index.js +94 -0
- package/avatar/types.d.ts +37 -0
- package/avatar/types.js +1 -0
- package/avatar/utils.d.ts +4 -0
- package/avatar/utils.js +7 -0
- package/badge/index.d.ts +11 -0
- package/badge/index.js +114 -0
- package/badge/types.d.ts +34 -0
- package/badge/types.js +1 -0
- package/badge/utils.d.ts +2 -0
- package/badge/utils.js +1 -0
- package/button/index.d.ts +11 -0
- package/button/index.js +182 -0
- package/button/types.d.ts +53 -0
- package/button/types.js +1 -0
- package/button/utils.d.ts +2 -0
- package/button/utils.js +1 -0
- package/card/index.d.ts +13 -0
- package/card/index.js +133 -0
- package/card/types.d.ts +28 -0
- package/card/types.js +1 -0
- package/card-container/index.d.ts +11 -0
- package/card-container/index.js +11 -0
- package/card-container/types.d.ts +3 -0
- package/card-container/types.js +1 -0
- package/chat/index.d.ts +11 -0
- package/chat/index.js +11 -0
- package/chat/types.d.ts +3 -0
- package/chat/types.js +1 -0
- package/chat-block/index.d.ts +11 -0
- package/chat-block/index.js +86 -0
- package/chat-block/types.d.ts +30 -0
- package/chat-block/types.js +1 -0
- package/chat-bubble/index.d.ts +11 -0
- package/chat-bubble/index.js +41 -0
- package/chat-bubble/types.d.ts +20 -0
- package/chat-bubble/types.js +1 -0
- package/chat-bubble/utils.d.ts +3 -0
- package/chat-bubble/utils.js +2 -0
- package/checkbox/index.d.ts +11 -0
- package/checkbox/index.js +126 -0
- package/checkbox/types.d.ts +49 -0
- package/checkbox/types.js +1 -0
- package/chip/index.d.ts +13 -0
- package/chip/index.js +144 -0
- package/chip/types.d.ts +37 -0
- package/chip/types.js +1 -0
- package/chip/utils.d.ts +2 -0
- package/chip/utils.js +6 -0
- package/code-tag/index.d.ts +11 -0
- package/code-tag/index.js +31 -0
- package/code-tag/types.d.ts +11 -0
- package/code-tag/types.js +1 -0
- package/color-menu/index.d.ts +11 -0
- package/color-menu/index.js +308 -0
- package/color-menu/types.d.ts +32 -0
- package/color-menu/types.js +1 -0
- package/color-menu/utils.d.ts +1 -0
- package/color-menu/utils.js +11 -0
- package/color-menu-option/index.d.ts +13 -0
- package/color-menu-option/index.js +48 -0
- package/color-menu-option/types.d.ts +11 -0
- package/color-menu-option/types.js +1 -0
- package/color-menu-option/utils.d.ts +1 -0
- package/color-menu-option/utils.js +11 -0
- package/color-swatch/index.d.ts +12 -0
- package/color-swatch/index.js +54 -0
- package/color-swatch/types.d.ts +11 -0
- package/color-swatch/types.js +1 -0
- package/color-swatch/utils.d.ts +2 -0
- package/color-swatch/utils.js +6 -0
- package/date-picker/index.d.ts +14 -0
- package/date-picker/index.js +381 -0
- package/date-picker/types.d.ts +70 -0
- package/date-picker/types.js +1 -0
- package/date-picker/utils.d.ts +28 -0
- package/date-picker/utils.js +142 -0
- package/dialog/index.d.ts +15 -0
- package/dialog/index.js +144 -0
- package/dialog/types.d.ts +28 -0
- package/dialog/types.js +1 -0
- package/dialog/utils.d.ts +2 -0
- package/dialog/utils.js +18 -0
- package/emoji/index.d.ts +11 -0
- package/emoji/index.js +46 -0
- package/emoji/types.d.ts +11 -0
- package/emoji/types.js +1 -0
- package/emoji/utils.d.ts +3 -0
- package/emoji/utils.js +47 -0
- package/emoji-picker/index.d.ts +22 -0
- package/emoji-picker/index.js +308 -0
- package/emoji-picker/types.d.ts +26 -0
- package/emoji-picker/types.js +1 -0
- package/field/index.d.ts +11 -0
- package/field/index.js +120 -0
- package/field/types.d.ts +35 -0
- package/field/types.js +1 -0
- package/file-drop/index.d.ts +13 -0
- package/file-drop/index.js +205 -0
- package/file-drop/types.d.ts +50 -0
- package/file-drop/types.js +1 -0
- package/file-drop/utils.d.ts +2 -0
- package/file-drop/utils.js +31 -0
- package/file-picker/index.d.ts +11 -0
- package/file-picker/index.js +103 -0
- package/file-picker/types.d.ts +32 -0
- package/file-picker/types.js +1 -0
- package/file-picker/utils.d.ts +1 -0
- package/file-picker/utils.js +8 -0
- package/file-status/index.d.ts +14 -0
- package/file-status/index.js +61 -0
- package/file-status/types.d.ts +18 -0
- package/file-status/types.js +1 -0
- package/file-status/utils.d.ts +2 -0
- package/file-status/utils.js +1 -0
- package/flag/index.d.ts +11 -0
- package/flag/index.js +46 -0
- package/flag/types.d.ts +11 -0
- package/flag/types.js +1 -0
- package/flag/utils.d.ts +1 -0
- package/flag/utils.js +17 -0
- package/grid/index.d.ts +11 -0
- package/grid/index.js +11 -0
- package/grid/types.d.ts +3 -0
- package/grid/types.js +1 -0
- package/grid-item/index.d.ts +11 -0
- package/grid-item/index.js +35 -0
- package/grid-item/types.d.ts +17 -0
- package/grid-item/types.js +1 -0
- package/help-tooltip/index.d.ts +13 -0
- package/help-tooltip/index.js +74 -0
- package/help-tooltip/types.d.ts +3 -0
- package/help-tooltip/types.js +1 -0
- package/horizontal-stepper/index.d.ts +11 -0
- package/horizontal-stepper/index.js +61 -0
- package/horizontal-stepper/types.d.ts +13 -0
- package/horizontal-stepper/types.js +1 -0
- package/horizontal-stepper-item/index.d.ts +14 -0
- package/horizontal-stepper-item/index.js +61 -0
- package/horizontal-stepper-item/types.d.ts +24 -0
- package/horizontal-stepper-item/types.js +1 -0
- package/horizontal-stepper-item/utils.d.ts +2 -0
- package/horizontal-stepper-item/utils.js +1 -0
- package/icon/index.d.ts +11 -0
- package/icon/index.js +32 -0
- package/icon/types.d.ts +11 -0
- package/icon/types.js +1 -0
- package/icon-button/index.d.ts +12 -0
- package/icon-button/index.js +175 -0
- package/icon-button/types.d.ts +44 -0
- package/icon-button/types.js +1 -0
- package/icon-button/utils.d.ts +2 -0
- package/icon-button/utils.js +1 -0
- package/inline-alert/index.d.ts +15 -0
- package/inline-alert/index.js +83 -0
- package/inline-alert/types.d.ts +15 -0
- package/inline-alert/types.js +1 -0
- package/inline-alert/utils.d.ts +2 -0
- package/inline-alert/utils.js +1 -0
- package/input/index.d.ts +11 -0
- package/input/index.js +642 -0
- package/input/types.d.ts +86 -0
- package/input/types.js +1 -0
- package/input/utils.d.ts +26 -0
- package/input/utils.js +302 -0
- package/link/index.d.ts +12 -0
- package/link/index.js +150 -0
- package/link/types.d.ts +59 -0
- package/link/types.js +1 -0
- package/list/index.d.ts +11 -0
- package/list/index.js +14 -0
- package/list/types.d.ts +3 -0
- package/list/types.js +1 -0
- package/list-item/index.d.ts +11 -0
- package/list-item/index.js +14 -0
- package/list-item/types.d.ts +3 -0
- package/list-item/types.js +1 -0
- package/package.json +1 -1
- package/pagination/index.d.ts +12 -0
- package/pagination/index.js +147 -0
- package/pagination/types.d.ts +16 -0
- package/pagination/types.js +1 -0
- package/pop/index.d.ts +11 -0
- package/pop/index.js +425 -0
- package/pop/types.d.ts +35 -0
- package/pop/types.js +1 -0
- package/pop/utils.d.ts +4 -0
- package/pop/utils.js +16 -0
- package/popover/index.d.ts +12 -0
- package/popover/index.js +146 -0
- package/popover/types.d.ts +38 -0
- package/popover/types.js +1 -0
- package/popover/utils.d.ts +4 -0
- package/popover/utils.js +10 -0
- package/progress/index.d.ts +12 -0
- package/progress/index.js +58 -0
- package/progress/types.d.ts +12 -0
- package/progress/types.js +1 -0
- package/progress-stepper/index.d.ts +11 -0
- package/progress-stepper/index.js +206 -0
- package/progress-stepper/types.d.ts +22 -0
- package/progress-stepper/types.js +1 -0
- package/progress-stepper-item/index.d.ts +12 -0
- package/progress-stepper-item/index.js +82 -0
- package/progress-stepper-item/types.d.ts +23 -0
- package/progress-stepper-item/types.js +1 -0
- package/progress-stepper-item/utils.d.ts +11 -0
- package/progress-stepper-item/utils.js +13 -0
- package/radio/index.d.ts +11 -0
- package/radio/index.js +154 -0
- package/radio/types.d.ts +14 -0
- package/radio/types.js +1 -0
- package/radio-option/index.d.ts +11 -0
- package/radio-option/index.js +79 -0
- package/radio-option/types.d.ts +18 -0
- package/radio-option/types.js +1 -0
- package/rich-text/index.d.ts +14 -0
- package/rich-text/index.js +75 -0
- package/rich-text/types.d.ts +12 -0
- package/rich-text/types.js +1 -0
- package/rich-text/utils.d.ts +7 -0
- package/rich-text/utils.js +107 -0
- package/rich-textarea/index.d.ts +11 -0
- package/rich-textarea/index.js +464 -0
- package/rich-textarea/types.d.ts +48 -0
- package/rich-textarea/types.js +1 -0
- package/rich-textarea/utils.d.ts +39 -0
- package/rich-textarea/utils.js +1730 -0
- package/segment/index.d.ts +12 -0
- package/segment/index.js +109 -0
- package/segment/types.d.ts +16 -0
- package/segment/types.js +1 -0
- package/segment/utils.d.ts +3 -0
- package/segment/utils.js +16 -0
- package/segment-collapse/index.d.ts +13 -0
- package/segment-collapse/index.js +60 -0
- package/segment-collapse/types.d.ts +11 -0
- package/segment-collapse/types.js +1 -0
- package/segmented-control/index.d.ts +11 -0
- package/segmented-control/index.js +85 -0
- package/segmented-control/types.d.ts +11 -0
- package/segmented-control/types.js +1 -0
- package/segmented-control-option/index.d.ts +11 -0
- package/segmented-control-option/index.js +95 -0
- package/segmented-control-option/types.d.ts +19 -0
- package/segmented-control-option/types.js +1 -0
- package/segmented-icon-control/index.d.ts +11 -0
- package/segmented-icon-control/index.js +101 -0
- package/segmented-icon-control/types.d.ts +14 -0
- package/segmented-icon-control/types.js +1 -0
- package/segmented-icon-control-option/index.d.ts +11 -0
- package/segmented-icon-control-option/index.js +82 -0
- package/segmented-icon-control-option/types.d.ts +16 -0
- package/segmented-icon-control-option/types.js +1 -0
- package/select-button/index.d.ts +13 -0
- package/select-button/index.js +202 -0
- package/select-button/types.d.ts +50 -0
- package/select-button/types.js +1 -0
- package/select-menu/index.d.ts +15 -0
- package/select-menu/index.js +339 -0
- package/select-menu/types.d.ts +41 -0
- package/select-menu/types.js +1 -0
- package/select-menu-option/index.d.ts +28 -0
- package/select-menu-option/index.js +65 -0
- package/select-menu-option/types.d.ts +26 -0
- package/select-menu-option/types.js +1 -0
- package/skeleton/index.d.ts +11 -0
- package/skeleton/index.js +108 -0
- package/skeleton/types.d.ts +9 -0
- package/skeleton/types.js +1 -0
- package/skeleton-item/index.d.ts +11 -0
- package/skeleton-item/index.js +11 -0
- package/skeleton-item/types.d.ts +13 -0
- package/skeleton-item/types.js +1 -0
- package/spinner/index.d.ts +11 -0
- package/spinner/index.js +58 -0
- package/spinner/types.d.ts +12 -0
- package/spinner/types.js +1 -0
- package/standalone.d.ts +85 -0
- package/standalone.js +87 -0
- package/stop-events/index.d.ts +1 -0
- package/stop-events/index.js +27 -0
- package/table/index.d.ts +11 -0
- package/table/index.js +14 -0
- package/table/types.d.ts +3 -0
- package/table/types.js +1 -0
- package/table-body/index.d.ts +11 -0
- package/table-body/index.js +14 -0
- package/table-body/types.d.ts +3 -0
- package/table-body/types.js +1 -0
- package/table-cell/index.d.ts +11 -0
- package/table-cell/index.js +21 -0
- package/table-cell/types.d.ts +9 -0
- package/table-cell/types.js +1 -0
- package/table-cell/utils.d.ts +2 -0
- package/table-cell/utils.js +1 -0
- package/table-head/index.d.ts +11 -0
- package/table-head/index.js +14 -0
- package/table-head/types.d.ts +3 -0
- package/table-head/types.js +1 -0
- package/table-head-cell/index.d.ts +12 -0
- package/table-head-cell/index.js +57 -0
- package/table-head-cell/types.d.ts +15 -0
- package/table-head-cell/types.js +1 -0
- package/table-row/index.d.ts +11 -0
- package/table-row/index.js +42 -0
- package/table-row/types.d.ts +11 -0
- package/table-row/types.js +1 -0
- package/tabs/index.d.ts +11 -0
- package/tabs/index.js +80 -0
- package/tabs/types.d.ts +18 -0
- package/tabs/types.js +1 -0
- package/tabs-icon-option/index.d.ts +11 -0
- package/tabs-icon-option/index.js +79 -0
- package/tabs-icon-option/types.d.ts +19 -0
- package/tabs-icon-option/types.js +1 -0
- package/tabs-option/index.d.ts +12 -0
- package/tabs-option/index.js +86 -0
- package/tabs-option/types.d.ts +25 -0
- package/tabs-option/types.js +1 -0
- package/tag/index.d.ts +12 -0
- package/tag/index.js +84 -0
- package/tag/types.d.ts +23 -0
- package/tag/types.js +1 -0
- package/tag/utils.d.ts +2 -0
- package/tag/utils.js +6 -0
- package/text/index.d.ts +11 -0
- package/text/index.js +64 -0
- package/text/types.d.ts +30 -0
- package/text/types.js +1 -0
- package/text/utils.d.ts +2 -0
- package/text/utils.js +1 -0
- package/textarea/index.d.ts +11 -0
- package/textarea/index.js +322 -0
- package/textarea/types.d.ts +60 -0
- package/textarea/types.js +1 -0
- package/tile-control/index.d.ts +11 -0
- package/tile-control/index.js +110 -0
- package/tile-control/types.d.ts +37 -0
- package/tile-control/types.js +1 -0
- package/tile-control-option/index.d.ts +11 -0
- package/tile-control-option/index.js +98 -0
- package/tile-control-option/types.d.ts +37 -0
- package/tile-control-option/types.js +1 -0
- package/time-picker/index.d.ts +15 -0
- package/time-picker/index.js +337 -0
- package/time-picker/types.d.ts +34 -0
- package/time-picker/types.js +1 -0
- package/time-picker/utils.d.ts +11 -0
- package/time-picker/utils.js +75 -0
- package/title/index.d.ts +11 -0
- package/title/index.js +60 -0
- package/title/types.d.ts +31 -0
- package/title/types.js +1 -0
- package/title/utils.d.ts +3 -0
- package/title/utils.js +17 -0
- package/toast/index.d.ts +13 -0
- package/toast/index.js +86 -0
- package/toast/types.d.ts +28 -0
- package/toast/types.js +1 -0
- package/toast/utils.d.ts +2 -0
- package/toast/utils.js +1 -0
- package/toast-manager/index.d.ts +13 -0
- package/toast-manager/index.js +170 -0
- package/toast-manager/types.d.ts +13 -0
- package/toast-manager/types.js +1 -0
- package/toast-manager/utils.d.ts +2 -0
- package/toast-manager/utils.js +1 -0
- package/toggle/index.d.ts +11 -0
- package/toggle/index.js +141 -0
- package/toggle/types.d.ts +23 -0
- package/toggle/types.js +1 -0
- package/tooltip/index.d.ts +13 -0
- package/tooltip/index.js +275 -0
- package/tooltip/tooltip-state.d.ts +19 -0
- package/tooltip/tooltip-state.js +126 -0
- package/tooltip/types.d.ts +42 -0
- package/tooltip/types.js +1 -0
- package/tooltip/utils.d.ts +6 -0
- package/tooltip/utils.js +18 -0
- package/utils/context.d.ts +20 -0
- package/utils/context.js +84 -0
- package/utils/countries.d.ts +6 -0
- package/utils/countries.js +2 -0
- package/utils/csv.d.ts +5 -0
- package/utils/csv.js +22 -0
- package/utils/debounce.d.ts +8 -0
- package/utils/debounce.js +22 -0
- package/utils/dom.d.ts +34 -0
- package/utils/dom.js +154 -0
- package/utils/element.d.ts +16 -0
- package/utils/element.js +48 -0
- package/utils/event-target.d.ts +4 -0
- package/utils/event-target.js +26 -0
- package/utils/get-react-event-handler.d.ts +1 -0
- package/utils/get-react-event-handler.js +8 -0
- package/utils/index.d.ts +12 -0
- package/utils/index.js +12 -0
- package/utils/markdown.d.ts +19 -0
- package/utils/markdown.js +143 -0
- package/utils/rect.d.ts +4 -0
- package/utils/rect.js +28 -0
- package/utils/size.d.ts +5 -0
- package/utils/size.js +3 -0
- package/utils/slot.d.ts +4 -0
- package/utils/slot.js +38 -0
- package/utils/throttle.d.ts +4 -0
- package/utils/throttle.js +20 -0
- package/utils/uid.d.ts +1 -0
- package/utils/uid.js +13 -0
- package/vertical-stepper/index.d.ts +11 -0
- package/vertical-stepper/index.js +57 -0
- package/vertical-stepper/types.d.ts +13 -0
- package/vertical-stepper/types.js +1 -0
- package/vertical-stepper-item/index.d.ts +14 -0
- package/vertical-stepper-item/index.js +61 -0
- package/vertical-stepper-item/types.d.ts +24 -0
- package/vertical-stepper-item/types.js +1 -0
- package/vertical-stepper-item/utils.d.ts +2 -0
- package/vertical-stepper-item/utils.js +1 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import '../title';
|
|
2
|
+
import type { TSinchSegmentElement, TSinchSegmentReact } from './types';
|
|
3
|
+
declare global {
|
|
4
|
+
namespace JSX {
|
|
5
|
+
interface IntrinsicElements {
|
|
6
|
+
'sinch-segment': TSinchSegmentReact;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
interface HTMLElementTagNameMap {
|
|
10
|
+
'sinch-segment': TSinchSegmentElement;
|
|
11
|
+
}
|
|
12
|
+
}
|
package/segment/index.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import '../title';
|
|
2
|
+
import { getTitleLevelFromType } from '../title/utils';
|
|
3
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, getLiteralAttribute, getRect, isAttrEqual, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute, updateLiteralAttribute } from '../utils';
|
|
4
|
+
import { DEFAULT_SIZE, sizeValues } from '../utils/size';
|
|
5
|
+
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:column;gap:12px;width:100%;height:100%;border:1px solid var(--sinch-comp-segment-color-default-border-initial);border-radius:var(--sinch-comp-segment-shape-radius);box-sizing:border-box;background-color:var(--sinch-comp-segment-color-default-background-initial);padding:8px 0 16px}#header{display:flex;flex-direction:row;align-items:center;height:48px;gap:8px;padding:0 24px}#icon{--sinch-global-size-icon:32px}#caption{min-width:1em;--sinch-comp-title-font:var(--sinch-comp-segment-font-size-m-title)}:host([size="l"]) #caption{--sinch-comp-title-font:var(--sinch-comp-segment-font-size-l-title)}:host([size="s"]) #caption{--sinch-comp-title-font:var(--sinch-comp-segment-font-size-s-title)}#info{display:flex;flex-direction:row;align-items:center;gap:8px;margin-left:auto;align-self:stretch}#info.empty{display:none}#preview{flex:1;flex-basis:auto;height:48px;min-width:0;overflow:hidden;margin-left:24px}#preview.empty{display:none}#info.empty+#collapse{margin-left:auto}#collapse.empty{display:none}#preview:not(.empty)+#info.empty+#collapse:not(.empty),#preview:not(.empty)+#info:not(.empty){margin-left:24px}#content-wrapper{flex:1;min-height:0;overflow-y:auto;padding:4px 24px}#action{display:flex;flex-direction:row;justify-content:flex-end;gap:16px;padding:0 24px}#action.empty{display:none}:host([collapsed]) :is(#content-wrapper,#action){display:none}:host([collapsed]) #wrapper{padding-bottom:8px}::slotted([slot=icon]){margin-right:8px}</style><div id="wrapper"><div id="header"><slot id="icon" name="icon"></slot><sinch-title id="caption" level="3" type="m" ellipsis></sinch-title><div id="preview"><slot name="preview"></slot></div><div id="info"><slot name="info"></slot></div><div id="collapse"><slot name="collapse"></slot></div></div><div id="content-wrapper"><slot name="content"></slot></div><div id="action"><slot name="action"></slot></div></div>';
|
|
6
|
+
import { getTitleTypeFromSize } from './utils';
|
|
7
|
+
const template = document.createElement('template');
|
|
8
|
+
template.innerHTML = templateHTML;
|
|
9
|
+
defineCustomElement('sinch-segment', class extends NectaryElement {
|
|
10
|
+
#$caption;
|
|
11
|
+
#$previewSlot;
|
|
12
|
+
#$previewWrapper;
|
|
13
|
+
#$infoSlot;
|
|
14
|
+
#$infoWrapper;
|
|
15
|
+
#$collapseSlot;
|
|
16
|
+
#$collapseWrapper;
|
|
17
|
+
#$actionSlot;
|
|
18
|
+
#$actionWrapper;
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
const shadowRoot = this.attachShadow();
|
|
22
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
23
|
+
this.#$caption = shadowRoot.querySelector('#caption');
|
|
24
|
+
this.#$previewSlot = shadowRoot.querySelector('slot[name="preview"]');
|
|
25
|
+
this.#$infoSlot = shadowRoot.querySelector('slot[name="info"]');
|
|
26
|
+
this.#$collapseSlot = shadowRoot.querySelector('slot[name="collapse"]');
|
|
27
|
+
this.#$actionSlot = shadowRoot.querySelector('slot[name="action"]');
|
|
28
|
+
this.#$previewWrapper = shadowRoot.querySelector('#preview');
|
|
29
|
+
this.#$infoWrapper = shadowRoot.querySelector('#info');
|
|
30
|
+
this.#$collapseWrapper = shadowRoot.querySelector('#collapse');
|
|
31
|
+
this.#$actionWrapper = shadowRoot.querySelector('#action');
|
|
32
|
+
}
|
|
33
|
+
connectedCallback() {
|
|
34
|
+
this.#$previewSlot.addEventListener('slotchange', this.#onPreviewSlotChange);
|
|
35
|
+
this.#$infoSlot.addEventListener('slotchange', this.#onInfoSlotChange);
|
|
36
|
+
this.#$collapseSlot.addEventListener('slotchange', this.#onCollapseSlotChange);
|
|
37
|
+
this.#$actionSlot.addEventListener('slotchange', this.#onActionSlotChange);
|
|
38
|
+
this.#onPreviewSlotChange();
|
|
39
|
+
this.#onInfoSlotChange();
|
|
40
|
+
this.#onCollapseSlotChange();
|
|
41
|
+
this.#onActionSlotChange();
|
|
42
|
+
}
|
|
43
|
+
disconnectedCallback() {
|
|
44
|
+
this.#$previewSlot.removeEventListener('slotchange', this.#onPreviewSlotChange);
|
|
45
|
+
this.#$infoSlot.removeEventListener('slotchange', this.#onInfoSlotChange);
|
|
46
|
+
this.#$collapseSlot.removeEventListener('slotchange', this.#onCollapseSlotChange);
|
|
47
|
+
this.#$actionSlot.removeEventListener('slotchange', this.#onActionSlotChange);
|
|
48
|
+
}
|
|
49
|
+
static get observedAttributes() {
|
|
50
|
+
return ['caption', 'collapsed', 'size'];
|
|
51
|
+
}
|
|
52
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
53
|
+
switch (name) {
|
|
54
|
+
case 'caption':
|
|
55
|
+
{
|
|
56
|
+
updateAttribute(this.#$caption, 'text', newVal);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case 'collapsed':
|
|
60
|
+
{
|
|
61
|
+
if (isAttrEqual(oldVal, newVal)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
updateBooleanAttribute(this, name, isAttrTrue(newVal));
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case 'size':
|
|
68
|
+
{
|
|
69
|
+
const titleType = getTitleTypeFromSize(this.size);
|
|
70
|
+
updateAttribute(this.#$caption, 'level', getTitleLevelFromType(titleType));
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
set caption(caption) {
|
|
76
|
+
updateAttribute(this, 'caption', caption);
|
|
77
|
+
}
|
|
78
|
+
get caption() {
|
|
79
|
+
return getAttribute(this, 'caption', '');
|
|
80
|
+
}
|
|
81
|
+
set collapsed(isChecked) {
|
|
82
|
+
updateBooleanAttribute(this, 'collapsed', isChecked);
|
|
83
|
+
}
|
|
84
|
+
get collapsed() {
|
|
85
|
+
return getBooleanAttribute(this, 'collapsed');
|
|
86
|
+
}
|
|
87
|
+
get size() {
|
|
88
|
+
return getLiteralAttribute(this, sizeValues, 'size', DEFAULT_SIZE);
|
|
89
|
+
}
|
|
90
|
+
set size(value) {
|
|
91
|
+
updateLiteralAttribute(this, sizeValues, 'size', value);
|
|
92
|
+
}
|
|
93
|
+
get collapseButtonRect() {
|
|
94
|
+
const $collapseButton = this.#$collapseSlot.assignedElements()[0];
|
|
95
|
+
return $collapseButton != null ? getRect($collapseButton) : null;
|
|
96
|
+
}
|
|
97
|
+
#onPreviewSlotChange = () => {
|
|
98
|
+
setClass(this.#$previewWrapper, 'empty', this.#$previewSlot.assignedElements().length === 0);
|
|
99
|
+
};
|
|
100
|
+
#onInfoSlotChange = () => {
|
|
101
|
+
setClass(this.#$infoWrapper, 'empty', this.#$infoSlot.assignedElements().length === 0);
|
|
102
|
+
};
|
|
103
|
+
#onCollapseSlotChange = () => {
|
|
104
|
+
setClass(this.#$collapseWrapper, 'empty', this.#$collapseSlot.assignedElements().length === 0);
|
|
105
|
+
};
|
|
106
|
+
#onActionSlotChange = () => {
|
|
107
|
+
setClass(this.#$actionWrapper, 'empty', this.#$actionSlot.assignedElements().length === 0);
|
|
108
|
+
};
|
|
109
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TRect, TSinchElementReact } from '../types';
|
|
2
|
+
import type { TSinchSize } from '../utils/size';
|
|
3
|
+
export type TSinchSegmentElement = HTMLElement & {
|
|
4
|
+
caption: string;
|
|
5
|
+
collapsed: boolean;
|
|
6
|
+
size: TSinchSize;
|
|
7
|
+
readonly collapseButtonRect: TRect | null;
|
|
8
|
+
setAttribute(name: 'caption', value: string): void;
|
|
9
|
+
setAttribute(name: 'collapsed', value: ''): void;
|
|
10
|
+
setAttribute(name: 'size', value: TSinchSize): void;
|
|
11
|
+
};
|
|
12
|
+
export type TSinchSegmentReact = TSinchElementReact<TSinchSegmentElement> & {
|
|
13
|
+
caption: string;
|
|
14
|
+
collapsed?: boolean;
|
|
15
|
+
size?: TSinchSize;
|
|
16
|
+
};
|
package/segment/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/segment/utils.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '../icon';
|
|
2
|
+
import '../icon-button';
|
|
3
|
+
import type { TSinchSegmentExpandElement, TSinchSegmentExpandReact } from './types';
|
|
4
|
+
declare global {
|
|
5
|
+
namespace JSX {
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
'sinch-segment-collapse': TSinchSegmentExpandReact;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
interface HTMLElementTagNameMap {
|
|
11
|
+
'sinch-segment-collapse': TSinchSegmentExpandElement;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import '../icon';
|
|
2
|
+
import '../icon-button';
|
|
3
|
+
import { defineCustomElement, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
|
|
4
|
+
const templateHTML = '<style>:host{display:block;--sinch-global-size-icon:32px}#icon-dropdown{display:block;will-change:transform;transform:rotate(180deg)}:host([value]:not([value=false])) #icon-dropdown{transform:rotate(0)}</style><sinch-icon-button id="button" size="s"><sinch-icon id="icon-dropdown" slot="icon" name="keyboard_arrow_down"></sinch-icon></sinch-icon-button>';
|
|
5
|
+
const template = document.createElement('template');
|
|
6
|
+
template.innerHTML = templateHTML;
|
|
7
|
+
defineCustomElement('sinch-segment-collapse', class extends NectaryElement {
|
|
8
|
+
#$button;
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
const shadowRoot = this.attachShadow();
|
|
12
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
13
|
+
this.#$button = shadowRoot.querySelector('#button');
|
|
14
|
+
}
|
|
15
|
+
connectedCallback() {
|
|
16
|
+
this.setAttribute('role', 'checkbox');
|
|
17
|
+
this.#$button.addEventListener('click', this.#onClick);
|
|
18
|
+
this.addEventListener('-change', this.#onChangeReactHandler);
|
|
19
|
+
}
|
|
20
|
+
disconnectedCallback() {
|
|
21
|
+
this.#$button.removeEventListener('click', this.#onClick);
|
|
22
|
+
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
23
|
+
}
|
|
24
|
+
static get observedAttributes() {
|
|
25
|
+
return ['value'];
|
|
26
|
+
}
|
|
27
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
28
|
+
switch (name) {
|
|
29
|
+
case 'value':
|
|
30
|
+
{
|
|
31
|
+
updateExplicitBooleanAttribute(this, 'aria-checked', isAttrTrue(newVal));
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
set value(isChecked) {
|
|
37
|
+
updateBooleanAttribute(this, 'value', isChecked);
|
|
38
|
+
}
|
|
39
|
+
get value() {
|
|
40
|
+
return getBooleanAttribute(this, 'value');
|
|
41
|
+
}
|
|
42
|
+
get focusable() {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
focus() {
|
|
46
|
+
this.#$button.focus();
|
|
47
|
+
}
|
|
48
|
+
blur() {
|
|
49
|
+
this.#$button.blur();
|
|
50
|
+
}
|
|
51
|
+
#onClick = () => {
|
|
52
|
+
const detail = !this.value;
|
|
53
|
+
this.dispatchEvent(new CustomEvent('-change', {
|
|
54
|
+
detail
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
#onChangeReactHandler = e => {
|
|
58
|
+
getReactEventHandler(this, 'on-change')?.(e);
|
|
59
|
+
};
|
|
60
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TSinchElementReact } from '../types';
|
|
2
|
+
export type TSinchSegmentExpandElement = HTMLElement & {
|
|
3
|
+
value: boolean;
|
|
4
|
+
addEventListener(type: '-change', listener: (e: CustomEvent<boolean>) => void): void;
|
|
5
|
+
setAttribute(name: 'value', value: string): void;
|
|
6
|
+
};
|
|
7
|
+
export type TSinchSegmentExpandReact = TSinchElementReact<TSinchSegmentExpandElement> & {
|
|
8
|
+
value: boolean;
|
|
9
|
+
'aria-label': string;
|
|
10
|
+
'on-change'?: (e: CustomEvent<boolean>) => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TSinchSegmentedControlElement, TSinchSegmentedControlReact } from './types';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace JSX {
|
|
4
|
+
interface IntrinsicElements {
|
|
5
|
+
'sinch-segmented-control': TSinchSegmentedControlReact;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface HTMLElementTagNameMap {
|
|
9
|
+
'sinch-segmented-control': TSinchSegmentedControlElement;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, getTargetByAttribute, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
2
|
+
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;width:100%;box-sizing:border-box;position:relative;z-index:0}</style><div id="wrapper"><slot></slot></div>';
|
|
3
|
+
const template = document.createElement('template');
|
|
4
|
+
template.innerHTML = templateHTML;
|
|
5
|
+
defineCustomElement('sinch-segmented-control', class extends NectaryElement {
|
|
6
|
+
#$slot;
|
|
7
|
+
#controller = null;
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
const shadowRoot = this.attachShadow();
|
|
11
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
12
|
+
this.#$slot = shadowRoot.querySelector('slot');
|
|
13
|
+
}
|
|
14
|
+
connectedCallback() {
|
|
15
|
+
this.#controller = new AbortController();
|
|
16
|
+
const {
|
|
17
|
+
signal
|
|
18
|
+
} = this.#controller;
|
|
19
|
+
const options = {
|
|
20
|
+
signal
|
|
21
|
+
};
|
|
22
|
+
this.role = 'tablist';
|
|
23
|
+
this.#$slot.addEventListener('slotchange', this.#onSlotChange, options);
|
|
24
|
+
this.#$slot.addEventListener('click', this.#onOptionClick, options);
|
|
25
|
+
this.#$slot.addEventListener('keydown', this.#onOptionKeydown, options);
|
|
26
|
+
this.addEventListener('-change', this.#onChangeReactHandler);
|
|
27
|
+
}
|
|
28
|
+
disconnectedCallback() {
|
|
29
|
+
this.#controller.abort();
|
|
30
|
+
this.#controller = null;
|
|
31
|
+
}
|
|
32
|
+
static get observedAttributes() {
|
|
33
|
+
return ['value'];
|
|
34
|
+
}
|
|
35
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
36
|
+
switch (name) {
|
|
37
|
+
case 'value':
|
|
38
|
+
{
|
|
39
|
+
this.#onValueChange(newVal);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
set value(value) {
|
|
45
|
+
updateAttribute(this, 'value', value);
|
|
46
|
+
}
|
|
47
|
+
get value() {
|
|
48
|
+
return getAttribute(this, 'value', '');
|
|
49
|
+
}
|
|
50
|
+
#onSlotChange = () => {
|
|
51
|
+
this.#onValueChange(this.value);
|
|
52
|
+
};
|
|
53
|
+
#onOptionClick = e => {
|
|
54
|
+
const target = getTargetByAttribute(e, 'value');
|
|
55
|
+
if (target === null || getBooleanAttribute(target, 'disabled')) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const value = getAttribute(target, 'value', '');
|
|
59
|
+
this.dispatchEvent(new CustomEvent('-change', {
|
|
60
|
+
detail: value
|
|
61
|
+
}));
|
|
62
|
+
};
|
|
63
|
+
#onOptionKeydown = e => {
|
|
64
|
+
switch (e.code) {
|
|
65
|
+
case 'Space':
|
|
66
|
+
case 'Enter':
|
|
67
|
+
{
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
const target = getTargetByAttribute(e, 'value');
|
|
70
|
+
if (target !== null) {
|
|
71
|
+
target.click();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
#onValueChange(value) {
|
|
77
|
+
for (const $option of this.#$slot.assignedElements()) {
|
|
78
|
+
const isChecked = !getBooleanAttribute($option, 'disabled') && value === getAttribute($option, 'value', '');
|
|
79
|
+
updateBooleanAttribute($option, 'data-checked', isChecked);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
#onChangeReactHandler = e => {
|
|
83
|
+
getReactEventHandler(this, 'on-change')?.(e);
|
|
84
|
+
};
|
|
85
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TSinchElementReact } from '../types';
|
|
2
|
+
export type TSinchSegmentedControlElement = HTMLElement & {
|
|
3
|
+
value: string;
|
|
4
|
+
addEventListener(type: '-change', listener: (e: CustomEvent<string>) => void): void;
|
|
5
|
+
setAttribute(name: 'value', value: string): void;
|
|
6
|
+
};
|
|
7
|
+
export type TSinchSegmentedControlReact = TSinchElementReact<TSinchSegmentedControlElement> & {
|
|
8
|
+
value: string;
|
|
9
|
+
'aria-label': string;
|
|
10
|
+
'on-change'?: (e: CustomEvent<string>) => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TSinchSegmentedControlOptionElement, TSinchSegmentedControlOptionReact } from './types';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace JSX {
|
|
4
|
+
interface IntrinsicElements {
|
|
5
|
+
'sinch-segmented-control-option': TSinchSegmentedControlOptionReact;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface HTMLElementTagNameMap {
|
|
9
|
+
'sinch-segmented-control-option': TSinchSegmentedControlOptionElement;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrEqual, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
|
|
2
|
+
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;gap:12px;width:100%;height:32px;padding:0 16px;box-sizing:border-box;color:var(--sinch-local-color-text);background-color:var(--sinch-local-color-background);cursor:pointer;--sinch-local-color-text:var(--sinch-comp-segmented-control-color-default-text-initial);--sinch-local-shape-radius:var(--sinch-comp-segmented-control-shape-radius);--sinch-local-color-border:var(--sinch-comp-segmented-control-color-default-border-initial);--sinch-local-color-background:var(--sinch-comp-segmented-control-color-default-background-initial);--sinch-global-color-icon:var(--sinch-comp-segmented-control-color-default-icon-initial);--sinch-global-size-icon:var(--sinch-comp-segmented-control-size-icon)}:host(:hover){--sinch-local-color-background:var(--sinch-comp-segmented-control-color-default-background-hover)}:host(:first-child) #wrapper{border-top-left-radius:var(--sinch-local-shape-radius);border-bottom-left-radius:var(--sinch-local-shape-radius)}:host(:last-child) #wrapper{border-top-right-radius:var(--sinch-local-shape-radius);border-bottom-right-radius:var(--sinch-local-shape-radius)}:host([data-checked]) #wrapper{--sinch-local-color-text:var(--sinch-comp-segmented-control-color-checked-text-initial);--sinch-global-color-icon:var(--sinch-comp-segmented-control-color-checked-icon-initial);--sinch-local-color-border:var(--sinch-comp-segmented-control-color-checked-border-initial);--sinch-local-color-background:var(--sinch-comp-segmented-control-color-checked-background-initial)}:host([disabled]) #wrapper{--sinch-local-color-text:var(--sinch-comp-segmented-control-color-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-segmented-control-color-disabled-icon-initial);--sinch-local-color-border:var(--sinch-comp-segmented-control-color-disabled-border-initial);--sinch-local-color-background:var(--sinch-comp-segmented-control-color-disabled-background-initial)}#border{position:absolute;inset:0;border:1px solid var(--sinch-local-color-border);pointer-events:none;box-sizing:border-box}:host(:first-child) #border{border-top-left-radius:var(--sinch-local-shape-radius);border-bottom-left-radius:var(--sinch-local-shape-radius)}:host(:last-child) #border{border-top-right-radius:var(--sinch-local-shape-radius);border-bottom-right-radius:var(--sinch-local-shape-radius)}:host(:not(:first-child)) #border{border-left-width:0}:host([data-checked]) #border{border-width:2px}:host([data-checked]:not(:first-child)) #border{left:-1px}#outline{display:none;position:absolute;inset:-3px;border:2px solid var(--sinch-comp-segmented-control-color-default-outline-focus);pointer-events:none;box-sizing:border-box;z-index:1}:host(:focus-visible) #outline{display:block}:host(:first-child) #outline{border-top-left-radius:calc(var(--sinch-local-shape-radius) + 3px);border-bottom-left-radius:calc(var(--sinch-local-shape-radius) + 3px)}:host(:last-child) #outline{border-top-right-radius:calc(var(--sinch-local-shape-radius) + 3px);border-bottom-right-radius:calc(var(--sinch-local-shape-radius) + 3px)}:host(:not(:first-child)) #outline{left:-4px}#content{font:var(--sinch-comp-segmented-control-font-label);flex-shrink:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;pointer-events:none}::slotted(*){display:block;pointer-events:none}</style><div id="wrapper"><slot name="icon"></slot><span id="content"></span><div id="border"></div><div id="outline"></div></div>';
|
|
3
|
+
const template = document.createElement('template');
|
|
4
|
+
template.innerHTML = templateHTML;
|
|
5
|
+
defineCustomElement('sinch-segmented-control-option', class extends NectaryElement {
|
|
6
|
+
#$label;
|
|
7
|
+
#controller = null;
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
const shadowRoot = this.attachShadow();
|
|
11
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
12
|
+
this.#$label = shadowRoot.querySelector('#content');
|
|
13
|
+
}
|
|
14
|
+
connectedCallback() {
|
|
15
|
+
this.#controller = new AbortController();
|
|
16
|
+
const {
|
|
17
|
+
signal
|
|
18
|
+
} = this.#controller;
|
|
19
|
+
const options = {
|
|
20
|
+
signal
|
|
21
|
+
};
|
|
22
|
+
this.role = 'tab';
|
|
23
|
+
this.addEventListener('focus', this.#onButtonFocus, options);
|
|
24
|
+
this.addEventListener('blur', this.#onButtonBlur, options);
|
|
25
|
+
this.addEventListener('-focus', this.#onFocusReactHandler);
|
|
26
|
+
this.addEventListener('-blur', this.#onBlurReactHandler);
|
|
27
|
+
this.#updateTabIndex();
|
|
28
|
+
}
|
|
29
|
+
disconnectedCallback() {
|
|
30
|
+
this.#controller.abort();
|
|
31
|
+
this.#controller = null;
|
|
32
|
+
}
|
|
33
|
+
static get observedAttributes() {
|
|
34
|
+
return ['data-checked', 'disabled', 'text'];
|
|
35
|
+
}
|
|
36
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
37
|
+
switch (name) {
|
|
38
|
+
case 'text':
|
|
39
|
+
{
|
|
40
|
+
this.#$label.textContent = newVal;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case 'data-checked':
|
|
44
|
+
{
|
|
45
|
+
updateExplicitBooleanAttribute(this, 'aria-selected', isAttrTrue(newVal));
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case 'disabled':
|
|
49
|
+
{
|
|
50
|
+
if (isAttrEqual(oldVal, newVal)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.#updateTabIndex();
|
|
54
|
+
updateBooleanAttribute(this, name, isAttrTrue(newVal));
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
set value(value) {
|
|
60
|
+
updateAttribute(this, 'value', value);
|
|
61
|
+
}
|
|
62
|
+
get value() {
|
|
63
|
+
return getAttribute(this, 'value', '');
|
|
64
|
+
}
|
|
65
|
+
set disabled(isDisabled) {
|
|
66
|
+
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
67
|
+
}
|
|
68
|
+
get disabled() {
|
|
69
|
+
return getBooleanAttribute(this, 'disabled');
|
|
70
|
+
}
|
|
71
|
+
set text(value) {
|
|
72
|
+
updateAttribute(this, 'text', value);
|
|
73
|
+
}
|
|
74
|
+
get text() {
|
|
75
|
+
return getAttribute(this, 'text', '');
|
|
76
|
+
}
|
|
77
|
+
get focusable() {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
#updateTabIndex() {
|
|
81
|
+
this.tabIndex = this.disabled ? -1 : 0;
|
|
82
|
+
}
|
|
83
|
+
#onButtonFocus = () => {
|
|
84
|
+
this.dispatchEvent(new CustomEvent('-focus'));
|
|
85
|
+
};
|
|
86
|
+
#onButtonBlur = () => {
|
|
87
|
+
this.dispatchEvent(new CustomEvent('-blur'));
|
|
88
|
+
};
|
|
89
|
+
#onFocusReactHandler = () => {
|
|
90
|
+
getReactEventHandler(this, 'on-focus')?.();
|
|
91
|
+
};
|
|
92
|
+
#onBlurReactHandler = () => {
|
|
93
|
+
getReactEventHandler(this, 'on-blur')?.();
|
|
94
|
+
};
|
|
95
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TSinchElementReact } from '../types';
|
|
2
|
+
export type TSinchSegmentedControlOptionElement = HTMLElement & {
|
|
3
|
+
value: string;
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
text: string;
|
|
6
|
+
addEventListener(type: '-focus', listener: (e: CustomEvent<void>) => void): void;
|
|
7
|
+
addEventListener(type: '-blur', listener: (e: CustomEvent<void>) => void): void;
|
|
8
|
+
setAttribute(name: 'value', value: string): void;
|
|
9
|
+
setAttribute(name: 'text', value: string): void;
|
|
10
|
+
setAttribute(name: 'disabled', value: ''): void;
|
|
11
|
+
};
|
|
12
|
+
export type TSinchSegmentedControlOptionReact = TSinchElementReact<TSinchSegmentedControlOptionElement> & {
|
|
13
|
+
value: string;
|
|
14
|
+
text: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
'aria-label': string;
|
|
17
|
+
'on-focus'?: (e: CustomEvent<void>) => void;
|
|
18
|
+
'on-blur'?: (e: CustomEvent<void>) => void;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TSinchSegmentedIconControlElement, TSinchSegmentedIconControlReact } from './types';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace JSX {
|
|
4
|
+
interface IntrinsicElements {
|
|
5
|
+
'sinch-segmented-icon-control': TSinchSegmentedIconControlReact;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface HTMLElementTagNameMap {
|
|
9
|
+
'sinch-segmented-icon-control': TSinchSegmentedIconControlElement;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, unpackCsv, getFirstCsvValue, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv, getTargetByAttribute } from '../utils';
|
|
2
|
+
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;width:100%;box-sizing:border-box;position:relative;z-index:0}</style><div id="wrapper"><slot></slot></div>';
|
|
3
|
+
const template = document.createElement('template');
|
|
4
|
+
template.innerHTML = templateHTML;
|
|
5
|
+
defineCustomElement('sinch-segmented-icon-control', class extends NectaryElement {
|
|
6
|
+
#$slot;
|
|
7
|
+
#controller = null;
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
const shadowRoot = this.attachShadow();
|
|
11
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
12
|
+
this.#$slot = shadowRoot.querySelector('slot');
|
|
13
|
+
}
|
|
14
|
+
connectedCallback() {
|
|
15
|
+
this.#controller = new AbortController();
|
|
16
|
+
const {
|
|
17
|
+
signal
|
|
18
|
+
} = this.#controller;
|
|
19
|
+
const options = {
|
|
20
|
+
signal
|
|
21
|
+
};
|
|
22
|
+
this.role = 'tablist';
|
|
23
|
+
this.#$slot.addEventListener('slotchange', this.#onSlotChange, options);
|
|
24
|
+
this.#$slot.addEventListener('click', this.#onOptionClick, options);
|
|
25
|
+
this.#$slot.addEventListener('keydown', this.#onOptionKeydown, options);
|
|
26
|
+
this.addEventListener('-change', this.#onChangeReactHandler, options);
|
|
27
|
+
}
|
|
28
|
+
disconnectedCallback() {
|
|
29
|
+
this.#controller.abort();
|
|
30
|
+
this.#controller = null;
|
|
31
|
+
}
|
|
32
|
+
static get observedAttributes() {
|
|
33
|
+
return ['value'];
|
|
34
|
+
}
|
|
35
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
36
|
+
switch (name) {
|
|
37
|
+
case 'value':
|
|
38
|
+
{
|
|
39
|
+
this.#onValueChange(newVal ?? '');
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
set value(value) {
|
|
45
|
+
updateAttribute(this, 'value', value);
|
|
46
|
+
}
|
|
47
|
+
get value() {
|
|
48
|
+
return getAttribute(this, 'value', '');
|
|
49
|
+
}
|
|
50
|
+
set multiple(isMultiple) {
|
|
51
|
+
updateBooleanAttribute(this, 'multiple', isMultiple);
|
|
52
|
+
}
|
|
53
|
+
get multiple() {
|
|
54
|
+
return getBooleanAttribute(this, 'multiple');
|
|
55
|
+
}
|
|
56
|
+
#onSlotChange = () => {
|
|
57
|
+
this.#onValueChange(this.value);
|
|
58
|
+
};
|
|
59
|
+
#onOptionClick = e => {
|
|
60
|
+
const target = getTargetByAttribute(e, 'value');
|
|
61
|
+
if (target === null || getBooleanAttribute(target, 'disabled')) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const value = getAttribute(target, 'value', '');
|
|
65
|
+
const detail = this.multiple ? updateCsv(this.value, value, !getBooleanAttribute(target, 'data-checked')) : value;
|
|
66
|
+
this.dispatchEvent(new CustomEvent('-change', {
|
|
67
|
+
detail
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
#onOptionKeydown = e => {
|
|
71
|
+
switch (e.code) {
|
|
72
|
+
case 'Space':
|
|
73
|
+
case 'Enter':
|
|
74
|
+
{
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
const target = getTargetByAttribute(e, 'value');
|
|
77
|
+
if (target !== null) {
|
|
78
|
+
target.click();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
#onValueChange(csv) {
|
|
84
|
+
if (this.multiple) {
|
|
85
|
+
const values = unpackCsv(csv);
|
|
86
|
+
for (const $option of this.#$slot.assignedElements()) {
|
|
87
|
+
const isChecked = !getBooleanAttribute($option, 'disabled') && values.includes(getAttribute($option, 'value', ''));
|
|
88
|
+
updateBooleanAttribute($option, 'data-checked', isChecked);
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
const value = getFirstCsvValue(csv);
|
|
92
|
+
for (const $option of this.#$slot.assignedElements()) {
|
|
93
|
+
const isChecked = !getBooleanAttribute($option, 'disabled') && value === getAttribute($option, 'value', '');
|
|
94
|
+
updateBooleanAttribute($option, 'data-checked', isChecked);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
#onChangeReactHandler = e => {
|
|
99
|
+
getReactEventHandler(this, 'on-change')?.(e);
|
|
100
|
+
};
|
|
101
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TSinchElementReact } from '../types';
|
|
2
|
+
export type TSinchSegmentedIconControlElement = HTMLElement & {
|
|
3
|
+
value: string;
|
|
4
|
+
multiple: boolean;
|
|
5
|
+
addEventListener(type: '-change', listener: (e: CustomEvent<string>) => void): void;
|
|
6
|
+
setAttribute(name: 'value', value: string): void;
|
|
7
|
+
setAttribute(name: 'multiple', value: ''): void;
|
|
8
|
+
};
|
|
9
|
+
export type TSinchSegmentedIconControlReact = TSinchElementReact<TSinchSegmentedIconControlElement> & {
|
|
10
|
+
value: string;
|
|
11
|
+
multiple?: boolean;
|
|
12
|
+
'aria-label': string;
|
|
13
|
+
'on-change'?: (e: CustomEvent<string>) => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TSinchSegmentedIconControlOptionElement, TSinchSegmentedIconControlOptionReact } from './types';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace JSX {
|
|
4
|
+
interface IntrinsicElements {
|
|
5
|
+
'sinch-segmented-icon-control-option': TSinchSegmentedIconControlOptionReact;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface HTMLElementTagNameMap {
|
|
9
|
+
'sinch-segmented-icon-control-option': TSinchSegmentedIconControlOptionElement;
|
|
10
|
+
}
|
|
11
|
+
}
|