From f240b953b490f5d13fc5d33b1f82aed9b7bb3cd0 Mon Sep 17 00:00:00 2001 From: tugcekucukoglu Date: Thu, 18 Apr 2024 17:15:29 +0300 Subject: [PATCH] Refactor #5612 - InputSwitch / ToggleSwitch --- components/lib/inputswitch/InputSwitch.d.ts | 179 ++------------ components/lib/inputswitch/InputSwitch.vue | 63 +---- .../inputswitch/style/InputSwitchStyle.d.ts | 4 +- .../lib/inputswitch/style/InputSwitchStyle.js | 21 +- .../{inputswitch => toggleswitch}/index.js | 26 +-- .../package.json | 0 .../{inputswitch => toggleswitch}/index.js | 0 .../package.json | 0 .../BaseToggleSwitch.vue} | 6 +- components/lib/toggleswitch/ToggleSwitch.d.ts | 220 ++++++++++++++++++ .../lib/toggleswitch/ToggleSwitch.spec.js | 20 ++ components/lib/toggleswitch/ToggleSwitch.vue | 66 ++++++ components/lib/toggleswitch/package.json | 9 + .../toggleswitch/style/ToggleSwitchStyle.d.ts | 3 + .../toggleswitch/style/ToggleSwitchStyle.js | 24 ++ .../lib/toggleswitch/style/package.json | 6 + 16 files changed, 384 insertions(+), 263 deletions(-) rename components/lib/themes/primeone/base/{inputswitch => toggleswitch}/index.js (71%) rename components/lib/themes/primeone/base/{inputswitch => toggleswitch}/package.json (100%) rename components/lib/themes/primeone/presets/aura/{inputswitch => toggleswitch}/index.js (100%) rename components/lib/themes/primeone/presets/aura/{inputswitch => toggleswitch}/package.json (100%) rename components/lib/{inputswitch/BaseInputSwitch.vue => toggleswitch/BaseToggleSwitch.vue} (91%) create mode 100755 components/lib/toggleswitch/ToggleSwitch.d.ts create mode 100644 components/lib/toggleswitch/ToggleSwitch.spec.js create mode 100755 components/lib/toggleswitch/ToggleSwitch.vue create mode 100644 components/lib/toggleswitch/package.json create mode 100644 components/lib/toggleswitch/style/ToggleSwitchStyle.d.ts create mode 100644 components/lib/toggleswitch/style/ToggleSwitchStyle.js create mode 100644 components/lib/toggleswitch/style/package.json diff --git a/components/lib/inputswitch/InputSwitch.d.ts b/components/lib/inputswitch/InputSwitch.d.ts index e2f589873..42c158eb7 100755 --- a/components/lib/inputswitch/InputSwitch.d.ts +++ b/components/lib/inputswitch/InputSwitch.d.ts @@ -2,207 +2,54 @@ * * InputSwitch is used to select a boolean value. * - * [Live Demo](https://www.primevue.org/inputswitch/) + * [Live Demo](https://www.primevue.org/toggleswitch/) * * @module inputswitch * */ -import { ComponentHooks } from '../basecomponent'; -import { PassThroughOptions } from '../passthrough'; -import { ClassComponent, DesignToken, GlobalComponentConstructor, PassThrough } from '../ts-helpers'; - -export declare type InputSwitchPassThroughOptionType = InputSwitchPassThroughAttributes | ((options: InputSwitchPassThroughMethodOptions) => InputSwitchPassThroughAttributes | string) | string | null | undefined; - +import * as ToggleSwitch from '../toggleswitch'; +import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; /** * Custom passthrough(pt) option method. */ -export interface InputSwitchPassThroughMethodOptions { - /** - * Defines instance. - */ - instance: any; - /** - * Defines valid properties. - */ - props: InputSwitchProps; - /** - * Defines current options. - */ - context: InputSwitchContext; - /** - * Defines valid attributes. - */ - attrs: any; - /** - * Defines parent options. - */ - parent: any; - /** - * Defines passthrough(pt) options in global config. - */ - global: object | undefined; -} +export interface InputSwitchPassThroughMethodOptions extends ToggleSwitch.ToggleSwitchPassThroughMethodOptions {} /** * Custom passthrough(pt) options. * @see {@link InputSwitchProps.pt} */ -export interface InputSwitchPassThroughOptions { - /** - * Used to pass attributes to the root's DOM element. - */ - root?: InputSwitchPassThroughOptionType; - /** - * Used to pass attributes to the input's DOM element. - */ - input?: InputSwitchPassThroughOptionType; - /** - * Used to pass attributes to the slider's DOM element. - */ - slider?: InputSwitchPassThroughOptionType; - /** - * Used to manage all lifecycle hooks. - * @see {@link BaseComponent.ComponentHooks} - */ - hooks?: ComponentHooks; -} +export interface InputSwitchPassThroughOptions extends ToggleSwitch.ToggleSwitchPassThroughOptions {} /** * Custom passthrough attributes for each DOM elements */ -export interface InputSwitchPassThroughAttributes { - [key: string]: any; -} +export interface InputSwitchPassThroughAttributes extends ToggleSwitch.ToggleSwitchPassThroughAttributes {} /** * Defines valid properties in InputSwitch component. */ -export interface InputSwitchProps { - /** - * Specifies whether a inputswitch should be checked or not. - * @defaultValue false - */ - modelValue?: boolean | string | undefined; - /** - * Value in checked state. - * @defaultValue true - */ - trueValue?: any; - /** - * Value in unchecked state. - * @defaultValue false - */ - falseValue?: any; - /** - * When present, it specifies that the component should have invalid state style. - * @defaultValue false - */ - invalid?: boolean | undefined; - /** - * When present, it specifies that the component should be disabled. - * @defaultValue false - */ - disabled?: boolean | undefined; - /** - * When present, it specifies that an input field is read-only. - * @default false - */ - readonly?: boolean | undefined; - /** - * Index of the element in tabbing order. - */ - tabindex?: number | undefined; - /** - * Identifier of the underlying input element. - */ - inputId?: string | undefined; - /** - * Style class of the input field. - */ - inputClass?: string | object | undefined; - /** - * Inline style of the input field. - */ - inputStyle?: object | undefined; - /** - * Establishes relationships between the component and label(s) where its value should be one or more element IDs. - */ - ariaLabelledby?: string | undefined; - /** - * Establishes a string value that labels the component. - */ - ariaLabel?: string | undefined; - /** - * It generates scoped CSS variables using design tokens for the component. - */ - dt?: DesignToken; - /** - * Used to pass attributes to DOM elements inside the component. - * @type {InputSwitchPassThroughOptions} - */ - pt?: PassThrough; - /** - * Used to configure passthrough(pt) options of the component. - * @type {PassThroughOptions} - */ - ptOptions?: PassThroughOptions; - /** - * When enabled, it removes component related styles in the core. - * @defaultValue false - */ - unstyled?: boolean; -} +export interface InputSwitchProps extends ToggleSwitch.ToggleSwitchProps {} /** * Defines current options in InputSwitch component. */ -export interface InputSwitchContext { - /** - * Current checked state of the item as a boolean. - * @defaultValue false - */ - checked: boolean; - /** - * Current disabled state of the item as a boolean. - * @defaultValue false - */ - disabled: boolean; -} +export interface InputSwitchContext extends ToggleSwitch.ToggleSwitchContext {} -export interface InputSwitchSlots {} +export interface InputSwitchSlots extends ToggleSwitch.ToggleSwitchSlots {} /** * Defines valid emits in InputSwitch component. */ -export interface InputSwitchEmits { - /** - * Emitted when the value changes. - * @param {boolean} value - New value. - */ - 'update:modelValue'(value: boolean): void; - /** - * Callback to invoke on value change. - * @param {Event} event - Browser event. - */ - change(event: Event): void; - /** - * Callback to invoke when the component receives focus. - * @param {Event} event - Browser event. - */ - focus(event: Event): void; - /** - * Callback to invoke when the component loses focus. - * @param {Event} event - Browser event. - */ - blur(event: Event): void; -} +export interface InputSwitchEmits extends ToggleSwitch.ToggleSwitchEmits {} /** + * @deprecated Deprecated since v4. Use ToggleSwitch component instead. + * * **PrimeVue - InputSwitch** * * _InputSwitch is used to select a boolean value._ * - * [Live Demo](https://www.primevue.org/inputswitch/) + * [Live Demo](https://www.primevue.org/toggleswitch/) * --- --- * ![PrimeVue](https://primefaces.org/cdn/primevue/images/logo-100.png) * diff --git a/components/lib/inputswitch/InputSwitch.vue b/components/lib/inputswitch/InputSwitch.vue index d6b397a77..253becd1f 100755 --- a/components/lib/inputswitch/InputSwitch.vue +++ b/components/lib/inputswitch/InputSwitch.vue @@ -1,66 +1,11 @@ - - diff --git a/components/lib/inputswitch/style/InputSwitchStyle.d.ts b/components/lib/inputswitch/style/InputSwitchStyle.d.ts index db09e4b82..0196ea577 100644 --- a/components/lib/inputswitch/style/InputSwitchStyle.d.ts +++ b/components/lib/inputswitch/style/InputSwitchStyle.d.ts @@ -1,3 +1,3 @@ -import { BaseStyle } from '../../base/style'; +import { ToggleSwitchStyle } from '../../toggleswitch/style/ToggleSwitchStyle'; -export interface InputSwitchStyle extends BaseStyle {} +export interface InputSwitchStyle extends ToggleSwitchStyle {} diff --git a/components/lib/inputswitch/style/InputSwitchStyle.js b/components/lib/inputswitch/style/InputSwitchStyle.js index 60e544693..a68537138 100644 --- a/components/lib/inputswitch/style/InputSwitchStyle.js +++ b/components/lib/inputswitch/style/InputSwitchStyle.js @@ -1,24 +1,5 @@ import BaseStyle from 'primevue/base/style'; -const inlineStyles = { - root: { position: 'relative' } -}; - -const classes = { - root: ({ instance, props }) => [ - 'p-toggleswitch p-component', - { - 'p-toggleswitch-checked': instance.checked, - 'p-disabled': props.disabled, - 'p-invalid': props.invalid - } - ], - input: 'p-toggleswitch-input', - slider: 'p-toggleswitch-slider' -}; - export default BaseStyle.extend({ - name: 'inputswitch', - classes, - inlineStyles + name: 'inputswitch' }); diff --git a/components/lib/themes/primeone/base/inputswitch/index.js b/components/lib/themes/primeone/base/toggleswitch/index.js similarity index 71% rename from components/lib/themes/primeone/base/inputswitch/index.js rename to components/lib/themes/primeone/base/toggleswitch/index.js index 0283940a8..af73cdd29 100644 --- a/components/lib/themes/primeone/base/inputswitch/index.js +++ b/components/lib/themes/primeone/base/toggleswitch/index.js @@ -19,7 +19,7 @@ export default { opacity: 0; z-index: 1; outline: 0 none; - border-radius: ${dt('inputswitch.border.radius')}; + border-radius: ${dt('toggleswitch.border.radius')}; } .p-toggleswitch-slider { @@ -30,9 +30,9 @@ export default { right: 0; bottom: 0; border: 0 none; - background: ${dt('inputswitch.background')}; + background: ${dt('toggleswitch.background')}; transition: background ${dt('transition.duration')}, color ${dt('transition.duration')}, border-color ${dt('transition.duration')}, box-shadow ${dt('transition.duration')}, outline-color ${dt('transition.duration')}; - border-radius: ${dt('inputswitch.border.radius')}; + border-radius: ${dt('toggleswitch.border.radius')}; outline-color: transparent; } @@ -40,38 +40,38 @@ export default { position: absolute; content: ""; top: 50%; - background: ${dt('inputswitch.handle.background')}; + background: ${dt('toggleswitch.handle.background')}; width: 1rem; height: 1rem; left: 0.25rem; margin-top: -0.5rem; - border-radius: ${dt('inputswitch.handle.border.radius')}; + border-radius: ${dt('toggleswitch.handle.border.radius')}; transition: all ${dt('transition.duration')}; } .p-toggleswitch.p-toggleswitch-checked .p-toggleswitch-slider { - background: ${dt('inputswitch.checked.background')}; + background: ${dt('toggleswitch.checked.background')}; } .p-toggleswitch.p-toggleswitch-checked .p-toggleswitch-slider:before { - background: ${dt('inputswitch.handle.checked.background')}; + background: ${dt('toggleswitch.handle.checked.background')}; left: 1.25rem; } .p-toggleswitch:not(.p-disabled):has(.p-toggleswitch-input:hover) .p-toggleswitch-slider { - background: ${dt('inputswitch.hover.background')}; + background: ${dt('toggleswitch.hover.background')}; } .p-toggleswitch:not(.p-disabled):has(.p-toggleswitch-input:hover) .p-toggleswitch-slider:before { - background: ${dt('inputswitch.handle.hover.background')}; + background: ${dt('toggleswitch.handle.hover.background')}; } .p-toggleswitch:not(.p-disabled):has(.p-toggleswitch-input:hover).p-toggleswitch-checked .p-toggleswitch-slider { - background: ${dt('inputswitch.checked.hover.background')}; + background: ${dt('toggleswitch.checked.hover.background')}; } .p-toggleswitch:not(.p-disabled):has(.p-toggleswitch-input:hover).p-toggleswitch-checked .p-toggleswitch-slider:before { - background: ${dt('inputswitch.handle.checked.hover.background')}; + background: ${dt('toggleswitch.handle.checked.hover.background')}; } .p-toggleswitch:not(.p-disabled):has(.p-toggleswitch-input:focus-visible) .p-toggleswitch-slider { @@ -80,11 +80,11 @@ export default { } .p-toggleswitch.p-invalid > .p-toggleswitch-slider { - background: ${dt('inputswitch.invalid.background')}; + background: ${dt('toggleswitch.invalid.background')}; } .p-toggleswitch.p-invalid > .p-toggleswitch-slider:before { - background: ${dt('inputswitch.handle.invalid.background')}; + background: ${dt('toggleswitch.handle.invalid.background')}; } ` }; diff --git a/components/lib/themes/primeone/base/inputswitch/package.json b/components/lib/themes/primeone/base/toggleswitch/package.json similarity index 100% rename from components/lib/themes/primeone/base/inputswitch/package.json rename to components/lib/themes/primeone/base/toggleswitch/package.json diff --git a/components/lib/themes/primeone/presets/aura/inputswitch/index.js b/components/lib/themes/primeone/presets/aura/toggleswitch/index.js similarity index 100% rename from components/lib/themes/primeone/presets/aura/inputswitch/index.js rename to components/lib/themes/primeone/presets/aura/toggleswitch/index.js diff --git a/components/lib/themes/primeone/presets/aura/inputswitch/package.json b/components/lib/themes/primeone/presets/aura/toggleswitch/package.json similarity index 100% rename from components/lib/themes/primeone/presets/aura/inputswitch/package.json rename to components/lib/themes/primeone/presets/aura/toggleswitch/package.json diff --git a/components/lib/inputswitch/BaseInputSwitch.vue b/components/lib/toggleswitch/BaseToggleSwitch.vue similarity index 91% rename from components/lib/inputswitch/BaseInputSwitch.vue rename to components/lib/toggleswitch/BaseToggleSwitch.vue index e259fee89..1c93d16dc 100644 --- a/components/lib/inputswitch/BaseInputSwitch.vue +++ b/components/lib/toggleswitch/BaseToggleSwitch.vue @@ -1,9 +1,9 @@ diff --git a/components/lib/toggleswitch/package.json b/components/lib/toggleswitch/package.json new file mode 100644 index 000000000..773ba8e0b --- /dev/null +++ b/components/lib/toggleswitch/package.json @@ -0,0 +1,9 @@ +{ + "main": "./toggleswitch.cjs.js", + "module": "./toggleswitch.esm.js", + "unpkg": "./toggleswitch.min.js", + "types": "./ToggleSwitch.d.ts", + "browser": { + "./sfc": "./ToggleSwitch.vue" + } +} diff --git a/components/lib/toggleswitch/style/ToggleSwitchStyle.d.ts b/components/lib/toggleswitch/style/ToggleSwitchStyle.d.ts new file mode 100644 index 000000000..57ba142a6 --- /dev/null +++ b/components/lib/toggleswitch/style/ToggleSwitchStyle.d.ts @@ -0,0 +1,3 @@ +import { BaseStyle } from '../../base/style'; + +export interface ToggleSwitchStyle extends BaseStyle {} diff --git a/components/lib/toggleswitch/style/ToggleSwitchStyle.js b/components/lib/toggleswitch/style/ToggleSwitchStyle.js new file mode 100644 index 000000000..2ac9d0293 --- /dev/null +++ b/components/lib/toggleswitch/style/ToggleSwitchStyle.js @@ -0,0 +1,24 @@ +import BaseStyle from 'primevue/base/style'; + +const inlineStyles = { + root: { position: 'relative' } +}; + +const classes = { + root: ({ instance, props }) => [ + 'p-toggleswitch p-component', + { + 'p-toggleswitch-checked': instance.checked, + 'p-disabled': props.disabled, + 'p-invalid': props.invalid + } + ], + input: 'p-toggleswitch-input', + slider: 'p-toggleswitch-slider' +}; + +export default BaseStyle.extend({ + name: 'toggleswitch', + classes, + inlineStyles +}); diff --git a/components/lib/toggleswitch/style/package.json b/components/lib/toggleswitch/style/package.json new file mode 100644 index 000000000..a4abf2e46 --- /dev/null +++ b/components/lib/toggleswitch/style/package.json @@ -0,0 +1,6 @@ +{ + "main": "./toggleswitchstyle.cjs.js", + "module": "./toggleswitchstyle.esm.js", + "unpkg": "./toggleswitchstyle.min.js", + "types": "./ToggleSwitchStyle.d.ts" +}