Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/basic/input-switch-polyfill.d.ts
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 8 additions & 2 deletions lib/basic/oui-checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { computed } from 'vue'

import './oui-form.styl'
import './oui-checkbox.styl'
import './switch-polyfill'

defineOptions({
inheritAttrs: false,
Expand Down Expand Up @@ -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: '' } : {}
})
</script>

<template>
<template v-if="title || $slots.default">
<label class="oui-form-item-checkbox" :class="{ _disabled: $attrs.disabled }">
<input v-model="modelBool" type="checkbox" :class="klass" v-bind="$attrs">
<input v-model="modelBool" type="checkbox" :class="klass" v-bind="{ ...$attrs, ...switchAttrs }">
{{ ' ' }}
<slot>{{ title }}</slot>
</label>
Expand All @@ -55,6 +61,6 @@ const klass = computed(() => {
</template>
</template>
<template v-else>
<input v-model="modelBool" type="checkbox" :class="klass" v-bind="$attrs">
<input v-model="modelBool" type="checkbox" :class="klass" v-bind="{ ...$attrs, ...switchAttrs }">
</template>
</template>
12 changes: 12 additions & 0 deletions lib/basic/switch-polyfill.ts
Original file line number Diff line number Diff line change
@@ -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')
}
})()
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down