Skip to content

Commit

Permalink
refactor(switch): ts to sfc (oku-ui#504)
Browse files Browse the repository at this point in the history
* refactor: switch ts to vue

* remove: useControllable

* chore: expose currentElement

* fix: aria-checked not present

* fix: data-disabled always appears

* chore: update snapshots

* Refactor switch component and add switch v-model tests
  • Loading branch information
Cr0zy07 authored Jan 18, 2024
1 parent 01730f9 commit 818fbf7
Show file tree
Hide file tree
Showing 19 changed files with 851 additions and 705 deletions.
2 changes: 1 addition & 1 deletion packages/package-build/switch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A control that allows the user to toggle between checked and not checked.

![@oku-ui/switch](./../../../.github/assets/og/oku-switch.jpg)

<span><a href="https://www.npmjs.com/package/@oku-ui/switch "><img src="https://img.shields.io/npm/v/@oku-ui/switch?style=flat&colorA=18181B&colorB=28CF8D" alt="Version"></a> </span> | <span> <a href="https://www.npmjs.com/package/@oku-ui/switch"> <img src="https://img.shields.io/npm/dm/@oku-ui/switch?style=flat&colorA=18181B&colorB=28CF8D" alt="Downloads"> </a> </span> | <span> <a href="https://oku-ui.com/primitives/components/switch"><img src="https://img.shields.io/badge/Open%20Documentation-18181B" alt="Website"></a> </span>
[![Version](https://img.shields.io/npm/v/@oku-ui/switch?style=flat&colorA=18181B&colorB=28CF8D)](https://www.npmjs.com/package/@oku-ui/switch) [![Downloads](https://img.shields.io/npm/dm/@oku-ui/switch?style=flat&colorA=18181B&colorB=28CF8D)](https://www.npmjs.com/package/@oku-ui/switch)

## Installation

Expand Down
103 changes: 0 additions & 103 deletions packages/vue/src/switch/BubbleInput.ts

This file was deleted.

56 changes: 56 additions & 0 deletions packages/vue/src/switch/BubbleInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<script lang="ts">
export interface BubbleInputProps {
checked: boolean
control: HTMLElement | null
bubbles: boolean
}
</script>

<script setup lang="ts">
import { computed, toRefs, watchEffect } from 'vue'
import { useComponentRef, usePrevious, useSize } from '@oku-ui/use-composable'
defineOptions({
name: 'OkuBubbleInput',
})
const props = defineProps<BubbleInputProps>()
const { checked, control } = toRefs(props)
const { componentRef, currentElement } = useComponentRef<HTMLInputElement | null>()
const prevChecked = usePrevious(checked)
const controlSize = computed(() => useSize(control))
// Bubble checked change to parents (e.g form change event)
watchEffect(() => {
const input = currentElement.value!
const inputProto = window.HTMLInputElement.prototype
const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked') as PropertyDescriptor
const setChecked = descriptor.set
if (prevChecked.value !== props.checked && setChecked) {
const event = new Event('click', { bubbles: props.bubbles })
setChecked.call(input, props.checked)
input.dispatchEvent(event)
}
})
</script>

<template>
<input
ref="componentRef"
type="checkbox"
:aria-hidden="true"
:defaultChecked="checked"
:tabIndex="-1"
:style="{
...$attrs.style as any,
...controlSize,
position: 'absolute',
pointerEvents: 'none',
opacity: 0,
margin: '0px',
}"
>
</template>
228 changes: 0 additions & 228 deletions packages/vue/src/switch/Switch.ts

This file was deleted.

Loading

0 comments on commit 818fbf7

Please sign in to comment.