UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 8.46 kB
{"version":3,"file":"switch.mjs","sources":["../../../../../../packages/components/switch/src/switch.ts"],"sourcesContent":["import {\n buildProps,\n definePropType,\n iconPropType,\n isBoolean,\n isNumber,\n isString,\n isValidComponentSize,\n} from '@element-plus/utils'\nimport {\n CHANGE_EVENT,\n INPUT_EVENT,\n UPDATE_MODEL_EVENT,\n} from '@element-plus/constants'\nimport { useAriaProps } from '@element-plus/hooks'\n\nimport type { ComponentSize } from '@element-plus/constants'\nimport type { Component, ExtractPublicPropTypes, PropType } from 'vue'\nimport type Switch from './switch.vue'\n\nexport interface SwitchProps {\n /**\n * @description binding value, it should be equivalent to either `active-value` or `inactive-value`, by default it's `boolean` type\n */\n modelValue?: boolean | string | number\n /**\n * @description whether Switch is disabled\n */\n disabled?: boolean\n /**\n * @description whether Switch is in loading state\n */\n loading?: boolean\n /**\n * @description size of Switch\n */\n size?: ComponentSize\n /**\n * @description width of Switch\n */\n width?: string | number\n /**\n * @description whether icon or text is displayed inside dot, only the first character will be rendered for text\n */\n inlinePrompt?: boolean\n /**\n * @description component of the icon displayed in action when in `off` state\n */\n inactiveActionIcon?: string | Component\n /**\n * @description component of the icon displayed in action when in `on` state\n */\n activeActionIcon?: string | Component\n /**\n * @description component of the icon displayed when in `on` state, overrides `active-text`\n */\n activeIcon?: string | Component\n /**\n * @description component of the icon displayed when in `off` state, overrides `inactive-text`\n */\n inactiveIcon?: string | Component\n /**\n * @description text displayed when in `on` state\n */\n activeText?: string\n /**\n * @description text displayed when in `off` state\n */\n inactiveText?: string\n /**\n * @description switch value when in `on` state\n */\n activeValue?: boolean | string | number\n /**\n * @description switch value when in `off` state\n */\n inactiveValue?: boolean | string | number\n /**\n * @description input name of Switch\n */\n name?: string\n /**\n * @description whether to trigger form validation\n */\n validateEvent?: boolean\n /**\n * @description before-change hook before the switch state changes. If `false` is returned or a `Promise` is returned and then is rejected, will stop switching\n */\n beforeChange?: () => Promise<boolean> | boolean\n /**\n * @description id for input\n */\n id?: string\n /**\n * @description tabindex for input\n */\n tabindex?: string | number\n /**\n * @description native `aria-label` attribute\n */\n ariaLabel?: string\n}\n\n/**\n * @deprecated Removed after 3.0.0, Use `SwitchProps` instead.\n */\nexport const switchProps = buildProps({\n /**\n * @description binding value, it should be equivalent to either `active-value` or `inactive-value`, by default it's `boolean` type\n */\n modelValue: {\n type: [Boolean, String, Number],\n default: false,\n },\n /**\n * @description whether Switch is disabled\n */\n disabled: {\n type: Boolean,\n default: undefined,\n },\n /**\n * @description whether Switch is in loading state\n */\n loading: Boolean,\n /**\n * @description size of Switch\n */\n size: {\n type: String as PropType<ComponentSize>,\n validator: isValidComponentSize,\n },\n /**\n * @description width of Switch\n */\n width: {\n type: [String, Number],\n default: '',\n },\n /**\n * @description whether icon or text is displayed inside dot, only the first character will be rendered for text\n */\n inlinePrompt: Boolean,\n /**\n * @description component of the icon displayed in action when in `off` state\n */\n inactiveActionIcon: {\n type: iconPropType,\n },\n /**\n * @description component of the icon displayed in action when in `on` state\n */\n activeActionIcon: {\n type: iconPropType,\n },\n /**\n * @description component of the icon displayed when in `on` state, overrides `active-text`\n */\n activeIcon: {\n type: iconPropType,\n },\n /**\n * @description component of the icon displayed when in `off` state, overrides `inactive-text`\n */\n inactiveIcon: {\n type: iconPropType,\n },\n /**\n * @description text displayed when in `on` state\n */\n activeText: {\n type: String,\n default: '',\n },\n /**\n * @description text displayed when in `off` state\n */\n inactiveText: {\n type: String,\n default: '',\n },\n /**\n * @description switch value when in `on` state\n */\n activeValue: {\n type: [Boolean, String, Number],\n default: true,\n },\n /**\n * @description switch value when in `off` state\n */\n inactiveValue: {\n type: [Boolean, String, Number],\n default: false,\n },\n /**\n * @description input name of Switch\n */\n name: {\n type: String,\n default: '',\n },\n /**\n * @description whether to trigger form validation\n */\n validateEvent: {\n type: Boolean,\n default: true,\n },\n /**\n * @description before-change hook before the switch state changes. If `false` is returned or a `Promise` is returned and then is rejected, will stop switching\n */\n beforeChange: {\n type: definePropType<() => Promise<boolean> | boolean>(Function),\n },\n /**\n * @description id for input\n */\n id: String,\n /**\n * @description tabindex for input\n */\n tabindex: {\n type: [String, Number],\n },\n ...useAriaProps(['ariaLabel']),\n} as const)\n\n/**\n * @deprecated Removed after 3.0.0, Use `SwitchProps` instead.\n */\nexport type SwitchPropsPublic = ExtractPublicPropTypes<typeof switchProps>\n\nexport const switchEmits = {\n [UPDATE_MODEL_EVENT]: (val: boolean | string | number) =>\n isBoolean(val) || isString(val) || isNumber(val),\n [CHANGE_EVENT]: (val: boolean | string | number) =>\n isBoolean(val) || isString(val) || isNumber(val),\n [INPUT_EVENT]: (val: boolean | string | number) =>\n isBoolean(val) || isString(val) || isNumber(val),\n}\nexport type SwitchEmits = typeof switchEmits\n\nexport type SwitchInstance = InstanceType<typeof Switch> & unknown\n"],"names":[],"mappings":";;;;;;;;AA0GO,MAAM,cAAc,UAAA,CAAW;AAAA;AAAA;AAAA;AAAA,EAIpC,UAAA,EAAY;AAAA,IACV,IAAA,EAAM,CAAC,OAAA,EAAS,MAAA,EAAQ,MAAM,CAAA;AAAA,IAC9B,OAAA,EAAS;AAAA,GACX;AAAA;AAAA;AAAA;AAAA,EAIA,QAAA,EAAU;AAAA,IACR,IAAA,EAAM,OAAA;AAAA,IACN,OAAA,EAAS;AAAA,GACX;AAAA;AAAA;AAAA;AAAA,EAIA,OAAA,EAAS,OAAA;AAAA;AAAA;AAAA;AAAA,EAIT,IAAA,EAAM;AAAA,IACJ,IAAA,EAAM,MAAA;AAAA,IACN,SAAA,EAAW;AAAA,GACb;AAAA;AAAA;AAAA;AAAA,EAIA,KAAA,EAAO;AAAA,IACL,IAAA,EAAM,CAAC,MAAA,EAAQ,MAAM,CAAA;AAAA,IACrB,OAAA,EAAS;AAAA,GACX;AAAA;AAAA;AAAA;AAAA,EAIA,YAAA,EAAc,OAAA;AAAA;AAAA;AAAA;AAAA,EAId,kBAAA,EAAoB;AAAA,IAClB,IAAA,EAAM;AAAA,GACR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