-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
137 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<script setup lang="ts"> | ||
import { ref, computed } from 'vue' | ||
defineOptions({ name: 'TCheckbox' }) | ||
const emit = defineEmits<{ click: [any] }>() | ||
const slots = defineSlots<{ default?(_: {}): any }>() | ||
const props = defineProps({value: { type: null, required: true }, | ||
name: String, | ||
disabled: Boolean, | ||
checked: { type: Boolean, default: undefined },}) | ||
const group = inject(CheckboxGroupInjectKey, null) | ||
console.log(parent) | ||
const [innerChecked, setInnerChecked] = useModelValue(props, { | ||
defaultValue: group ? group.value.value.includes(props.value) : false, | ||
valuePropName: 'checked', | ||
onChange: (val: boolean) => { | ||
emit('change', val) | ||
if (group) { | ||
if (val) { | ||
group.insert(props.value) | ||
} else { | ||
group.remove(props.value) | ||
} | ||
} | ||
}, | ||
}) | ||
const checked = computed(() => (group ? group.value.value.includes(props.value) : innerChecked.value)) | ||
const onInput = (e: Event) => { | ||
const el = e.currentTarget as HTMLInputElement | ||
console.log(el.checked) | ||
setInnerChecked(el.checked) | ||
} | ||
</script> | ||
<template> | ||
<label | ||
class={[ | ||
'relative inline-flex items-center', | ||
props.disabled ? 'cursor-not-allowed opacity-50' : 'cursor-pointer', | ||
]} | ||
> | ||
<input | ||
class="form-input h-4 w-4 rounded border-gray-300 text-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-500" | ||
style={{ boxShadow: 'none', cursor: 'inherit' }} | ||
type="checkbox" | ||
name={props.name} | ||
disabled={props.disabled} | ||
checked={checked.value} | ||
onInput={onInput} | ||
/> | ||
{slots.default ? <span class="relative ml-2 text-sm font-medium">{slots.default()}</span> : null} | ||
</label> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script setup lang="ts"> | ||
import { ref, computed } from 'vue' | ||
defineOptions({ name: 'TCheckboxGroup' }) | ||
const emit = defineEmits<{ click: [any] }>() | ||
const slots = defineSlots<{ default?(_: {}): any }>() | ||
const props = defineProps({ name: String, value: Array as PropType<unknown[]>, disabled: Boolean }) | ||
const [state, setState] = useModelValue<unknown[]>(props, { | ||
defaultValue: [], | ||
onChange: (val: any[]) => { | ||
emit('change', val) | ||
}, | ||
}) | ||
provide(CheckboxGroupInjectKey, { | ||
value: state, | ||
props: props, | ||
insert: (val: unknown) => { | ||
if (state.value.indexOf(val) === -1) { | ||
setState([...state.value, val]) | ||
} | ||
}, | ||
remove: (val: unknown) => { | ||
const index = state.value.indexOf(val) | ||
if (index !== -1) { | ||
const r = [...state.value] | ||
r.splice(index, 1) | ||
setState(r) | ||
} | ||
}, | ||
}) | ||
</script> | ||
<template> | ||
<div></div> | ||
</template> | ||
<style lang="scss"></style> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script setup lang="ts"> | ||
defineOptions({ name: 'LoadingIcon' }) | ||
</script> | ||
<template> | ||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> | ||
<circle opacity="0.25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" /> | ||
<path | ||
opacity="0.75" | ||
fill="currentColor" | ||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" | ||
/> | ||
</svg> | ||
</template> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters