-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
1 parent
a5e3cae
commit a73bd8f
Showing
17 changed files
with
370 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@zag-js/date-picker": patch | ||
--- | ||
|
||
Fix issue in Vue.js where input value could not be changed by typing. |
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
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,129 @@ | ||
<script setup lang="ts"> | ||
import * as datePicker from "@zag-js/date-picker" | ||
import { datePickerControls } from "@zag-js/shared" | ||
import { normalizeProps, useMachine } from "@zag-js/vue" | ||
import { computed } from "vue" | ||
const controls = useControls(datePickerControls) | ||
const [state, send] = useMachine( | ||
datePicker.machine({ | ||
id: "1", | ||
name: "date[]", | ||
locale: "en", | ||
numOfMonths: 2, | ||
selectionMode: "range", | ||
}), | ||
{ | ||
context: controls.context, | ||
}, | ||
) | ||
const api = computed(() => datePicker.connect(state.value, send, normalizeProps)) | ||
const offset = computed(() => api.value.getOffset({ months: 1 })) | ||
</script> | ||
|
||
<template> | ||
<main class="date-picker"> | ||
<div> | ||
<button>Outside Element</button> | ||
</div> | ||
<p>{{ `Visible range: ${api.visibleRangeText.formatted}` }}</p> | ||
|
||
<output class="date-output"> | ||
<div>Selected: {{ api.valueAsString.join(", ") ?? "-" }}</div> | ||
<div>Focused: {{ api.focusedValueAsString }}</div> | ||
</output> | ||
|
||
<div v-bind="api.getControlProps()"> | ||
<input v-bind="api.getInputProps({ index: 0 })" /> | ||
<input v-bind="api.getInputProps({ index: 1 })" /> | ||
<button v-bind="api.getClearTriggerProps()">❌</button> | ||
<button v-bind="api.getTriggerProps()">🗓</button> | ||
</div> | ||
|
||
<div v-bind="api.getPositionerProps()"> | ||
<div v-bind="api.getContentProps()"> | ||
<div style="margin-bottom: 20px"> | ||
<select v-bind="api.getMonthSelectProps()"> | ||
<option v-for="(month, i) in api.getMonths()" :key="i" :value="i + 1"> | ||
{{ month.label }} | ||
</option> | ||
</select> | ||
|
||
<select v-bind="api.getYearSelectProps()"> | ||
<option v-for="(year, i) in api.getYears()" :key="i" :value="year.value"> | ||
{{ year.label }} | ||
</option> | ||
</select> | ||
</div> | ||
|
||
<div> | ||
<div v-bind="api.getViewControlProps({ view: 'year' })"> | ||
<button v-bind="api.getPrevTriggerProps()">Prev</button> | ||
<span> {{ api.visibleRangeText.start }} - {{ api.visibleRangeText.end }} </span> | ||
<button v-bind="api.getNextTriggerProps()">Next</button> | ||
</div> | ||
|
||
<div style="display: flex; gap: 24px"> | ||
<table v-bind="api.getTableProps()"> | ||
<thead v-bind="api.getTableHeaderProps()"> | ||
<tr v-bind="api.getTableRowProps()"> | ||
<th v-for="(day, i) in api.weekDays" :key="i" scope="col" :aria-label="day.long"> | ||
{{ day.narrow }} | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody v-bind="api.getTableBodyProps()"> | ||
<tr v-for="(week, i) in api.weeks" :key="i" v-bind="api.getTableRowProps()"> | ||
<td v-for="(value, i) in week" :key="i" v-bind="api.getDayTableCellProps({ value })"> | ||
<div v-bind="api.getDayTableCellTriggerProps({ value })">{{ value.day }}</div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<table v-bind="api.getTableProps()"> | ||
<thead v-bind="api.getTableHeaderProps()"> | ||
<tr v-bind="api.getTableRowProps()"> | ||
<th v-for="(day, i) in api.weekDays" :key="i" scope="col" :aria-label="day.long"> | ||
{{ day.narrow }} | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody v-bind="api.getTableBodyProps()"> | ||
<tr v-for="(week, i) in offset.weeks" :key="i" v-bind="api.getTableRowProps()"> | ||
<td | ||
v-for="(value, i) in week" | ||
:key="i" | ||
v-bind="api.getDayTableCellProps({ value, visibleRange: offset.visibleRange })" | ||
> | ||
<div v-bind="api.getDayTableCellTriggerProps({ value, visibleRange: offset.visibleRange })"> | ||
{{ value.day }} | ||
</div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<div style="min-width: 80px; display: flex; flex-direction: column; gap: 4px"> | ||
<b>Presets</b> | ||
<button v-bind="api.getPresetTriggerProps({ value: 'last3Days' })">Last 3 Days</button> | ||
<button v-bind="api.getPresetTriggerProps({ value: 'last7Days' })">Last 7 Days</button> | ||
<button v-bind="api.getPresetTriggerProps({ value: 'last14Days' })">Last 14 Days</button> | ||
<button v-bind="api.getPresetTriggerProps({ value: 'last30Days' })">Last 30 Days</button> | ||
<button v-bind="api.getPresetTriggerProps({ value: 'last90Days' })">Last 90 Days</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
|
||
<Toolbar viz> | ||
<StateVisualizer :state="state" :omit="['weeks']" /> | ||
<template #controls> | ||
<Controls :control="controls" /> | ||
</template> | ||
</Toolbar> | ||
</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,146 @@ | ||
<script setup lang="ts"> | ||
import * as datePicker from "@zag-js/date-picker" | ||
import { datePickerControls } from "@zag-js/shared" | ||
import { normalizeProps, useMachine } from "@zag-js/vue" | ||
import { computed } from "vue" | ||
const controls = useControls(datePickerControls) | ||
const [state, send] = useMachine( | ||
datePicker.machine({ | ||
id: "1", | ||
locale: "en", | ||
selectionMode: "single", | ||
}), | ||
{ | ||
context: controls.context, | ||
}, | ||
) | ||
const api = computed(() => datePicker.connect(state.value, send, normalizeProps)) | ||
</script> | ||
|
||
<template> | ||
<main class="date-picker"> | ||
<div> | ||
<button>Outside Element</button> | ||
</div> | ||
<p>{{ `Visible range: ${api.visibleRangeText.formatted}` }}</p> | ||
|
||
<output class="date-output"> | ||
<div>Selected: {{ api.valueAsString ?? "-" }}</div> | ||
<div>Focused: {{ api.focusedValueAsString }}</div> | ||
</output> | ||
|
||
<div v-bind="api.getControlProps()"> | ||
<input v-bind="api.getInputProps()" /> | ||
<input v-bind="api.getInputProps()" /> | ||
<button v-bind="api.getClearTriggerProps()">❌</button> | ||
<button v-bind="api.getTriggerProps()">🗓</button> | ||
</div> | ||
|
||
<div v-bind="api.getPositionerProps()"> | ||
<div v-bind="api.getContentProps()"> | ||
<div style="margin-bottom: 20px"> | ||
<select v-bind="api.getMonthSelectProps()"> | ||
<option v-for="(month, i) in api.getMonths()" :key="i" :value="month.value"> | ||
{{ month.label }} | ||
</option> | ||
</select> | ||
|
||
<select v-bind="api.getYearSelectProps()"> | ||
<option v-for="(year, i) in api.getYears()" :key="i" :value="year.value"> | ||
{{ year.label }} | ||
</option> | ||
</select> | ||
</div> | ||
|
||
<div v-if="api.view === 'day'"> | ||
<div v-bind="api.getViewControlProps({ view: 'year' })"> | ||
<button v-bind="api.getPrevTriggerProps()">Prev</button> | ||
<button v-bind="api.getViewTriggerProps()">{{ api.visibleRangeText.start }}</button> | ||
<button v-bind="api.getNextTriggerProps()">Next</button> | ||
</div> | ||
|
||
<table v-bind="api.getTableProps({ view: 'day' })"> | ||
<thead v-bind="api.getTableHeaderProps({ view: 'day' })"> | ||
<tr v-bind="api.getTableRowProps({ view: 'day' })"> | ||
<th v-for="(day, i) in api.weekDays" :key="i" scope="col" :aria-label="day.long"> | ||
{{ day.narrow }} | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody v-bind="api.getTableBodyProps({ view: 'day' })"> | ||
<tr v-for="(week, i) in api.weeks" :key="i" v-bind="api.getTableRowProps({ view: 'day' })"> | ||
<td v-for="(value, i) in week" :key="i" v-bind="api.getDayTableCellProps({ value })"> | ||
<div v-bind="api.getDayTableCellTriggerProps({ value })">{{ value.day }}</div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<div style="display: flex; gap: 40px"> | ||
<div v-if="api.view === 'month'" style="width: 100%"> | ||
<div v-bind="api.getViewControlProps({ view: 'month' })"> | ||
<button v-bind="api.getPrevTriggerProps({ view: 'month' })">Prev</button> | ||
<button v-bind="api.getViewTriggerProps({ view: 'month' })">{{ api.visibleRange.start.year }}</button> | ||
<button v-bind="api.getNextTriggerProps({ view: 'month' })">Next</button> | ||
</div> | ||
|
||
<table v-bind="api.getTableProps({ view: 'month', columns: 4 })"> | ||
<tbody v-bind="api.getTableBodyProps()"> | ||
<tr | ||
v-for="(months, row) in api.getMonthsGrid({ columns: 4, format: 'short' })" | ||
:key="row" | ||
v-bind="api.getTableRowProps()" | ||
> | ||
<td | ||
v-for="(month, index) in months" | ||
:key="index" | ||
v-bind="api.getMonthTableCellProps({ ...month, columns: 4 })" | ||
> | ||
<div v-bind="api.getMonthTableCellTriggerProps({ ...month, columns: 4 })">{{ month.label }}</div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<div v-if="api.view === 'year'" style="width: 100%"> | ||
<div v-bind="api.getViewControlProps({ view: 'year' })"> | ||
<button v-bind="api.getPrevTriggerProps({ view: 'year' })">Prev</button> | ||
<span> {{ api.getDecade().start }} - {{ api.getDecade().end }} </span> | ||
<button v-bind="api.getNextTriggerProps({ view: 'year' })">Next</button> | ||
</div> | ||
|
||
<table v-bind="api.getTableProps({ view: 'year', columns: 4 })"> | ||
<tbody v-bind="api.getTableBodyProps()"> | ||
<tr | ||
v-for="(years, row) in api.getYearsGrid({ columns: 4 })" | ||
:key="row" | ||
v-bind="api.getTableRowProps({ view: 'year' })" | ||
> | ||
<td | ||
v-for="(year, index) in years" | ||
:key="index" | ||
v-bind="api.getYearTableCellProps({ ...year, columns: 4 })" | ||
> | ||
<div v-bind="api.getYearTableCellTriggerProps({ ...year, columns: 4 })">{{ year.label }}</div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
|
||
<Toolbar viz> | ||
<StateVisualizer :state="state" :omit="['weeks']" /> | ||
<template #controls> | ||
<Controls :control="controls" /> | ||
</template> | ||
</Toolbar> | ||
</template> |
Oops, something went wrong.