diff --git a/lib/basic/input-switch-polyfill.d.ts b/lib/basic/input-switch-polyfill.d.ts new file mode 100644 index 0000000..84d5c01 --- /dev/null +++ b/lib/basic/input-switch-polyfill.d.ts @@ -0,0 +1,10 @@ +// Type definitions for input-switch-polyfill +declare module 'input-switch-polyfill' { + // The polyfill is a side-effect only module +} + +declare module 'input-switch-polyfill/input-switch-polyfill.css' { + // CSS module + const css: string + export default css +} diff --git a/lib/basic/oui-checkbox.vue b/lib/basic/oui-checkbox.vue index c00dfa7..8c5b682 100644 --- a/lib/basic/oui-checkbox.vue +++ b/lib/basic/oui-checkbox.vue @@ -3,6 +3,7 @@ import { computed } from 'vue' import './oui-form.styl' import './oui-checkbox.styl' +import './switch-polyfill' defineOptions({ inheritAttrs: false, @@ -37,12 +38,17 @@ const klass = computed(() => { klasses.push('_checkbox_intermediate') return klasses }) + +const switchAttrs = computed(() => { + // Add the 'switch' attribute for the polyfill when switch prop is true + return props.switch ? { switch: '' } : {} +}) diff --git a/lib/basic/switch-polyfill.ts b/lib/basic/switch-polyfill.ts new file mode 100644 index 0000000..d5a0801 --- /dev/null +++ b/lib/basic/switch-polyfill.ts @@ -0,0 +1,12 @@ +// Polyfill for the HTML switch element +// https://github.com/tomayac/input-switch-polyfill + +// Import the polyfill CSS +import 'input-switch-polyfill/input-switch-polyfill.css' + +// Only load the polyfill if the browser doesn't support the switch attribute +;(async () => { + if (!('switch' in HTMLInputElement.prototype)) { + await import('input-switch-polyfill') + } +})() diff --git a/package.json b/package.json index cd0052b..4d3bc4b 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,7 @@ "dependencies": { "@floating-ui/vue": "^1.1.9", "@vueuse/core": "^14.1.0", + "input-switch-polyfill": "^1.9.0", "vue": "^3.5.25", "zeed": "^1.1.1" },