@surstromming/date-picker 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +87 -0
- package/package.json +52 -0
- package/src/DatePicker.vue +98 -0
- package/src/index.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Evgeniy Mnatsakanov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @surstromming/date-picker
|
|
2
|
+
|
|
3
|
+
A field-shaped trigger that opens a [`Calendar`](../calendar) in a
|
|
4
|
+
[`Popover`](../popover). Pure composition — it owns the open state, the label,
|
|
5
|
+
and nothing else.
|
|
6
|
+
|
|
7
|
+
## Dependency graph
|
|
8
|
+
|
|
9
|
+
```mermaid
|
|
10
|
+
graph LR
|
|
11
|
+
date_picker["@surstromming/date-picker"]
|
|
12
|
+
button["@surstromming/button"]
|
|
13
|
+
calendar["@surstromming/calendar"]
|
|
14
|
+
design["@surstromming/design"]
|
|
15
|
+
icon["@surstromming/icon"]
|
|
16
|
+
popover["@surstromming/popover"]
|
|
17
|
+
scroll_area["@surstromming/scroll-area"]
|
|
18
|
+
util["@surstromming/util"]
|
|
19
|
+
date_picker --> button
|
|
20
|
+
button --> design
|
|
21
|
+
date_picker --> calendar
|
|
22
|
+
calendar --> button
|
|
23
|
+
calendar --> design
|
|
24
|
+
calendar --> icon
|
|
25
|
+
date_picker --> design
|
|
26
|
+
date_picker --> icon
|
|
27
|
+
date_picker --> popover
|
|
28
|
+
popover --> design
|
|
29
|
+
popover --> scroll_area
|
|
30
|
+
scroll_area --> design
|
|
31
|
+
scroll_area --> util
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```vue
|
|
37
|
+
<template>
|
|
38
|
+
<Label id="due-label">Due date</Label>
|
|
39
|
+
<DatePicker v-model="due" :min="today" aria-labelledby="due-label" />
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<script setup lang="ts">
|
|
43
|
+
import { ref } from 'vue'
|
|
44
|
+
import { DatePicker } from '@surstromming/date-picker'
|
|
45
|
+
|
|
46
|
+
const due = ref<Date | null>(null)
|
|
47
|
+
const today = new Date()
|
|
48
|
+
</script>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Props
|
|
52
|
+
|
|
53
|
+
| Prop | Type | Default | Notes |
|
|
54
|
+
| --------------- | -------------------------- | -------------- | -------------------------------------------- |
|
|
55
|
+
| `v-model` | `Date \| null` | `null` | The selected day |
|
|
56
|
+
| `v-model:open` | `boolean` | `false` | Bindable if the app has to drive it |
|
|
57
|
+
| `placeholder` | `string` | `'Pick a date'`| Shown while nothing is selected |
|
|
58
|
+
| `format` | `(date: Date) => string` | — | Overrides the default `Intl` medium date |
|
|
59
|
+
| `min` / `max` | `Date` | — | Forwarded to the calendar |
|
|
60
|
+
| `isDisabled` | `(date: Date) => boolean` | — | Forwarded to the calendar |
|
|
61
|
+
| `weekStartsOn` | `sunday \| monday` | `monday` | Forwarded to the calendar |
|
|
62
|
+
| `locale` | `string` | — | Label and calendar; omitted means the browser's |
|
|
63
|
+
| `disabled` | `boolean` | `false` | |
|
|
64
|
+
|
|
65
|
+
### Fallthrough
|
|
66
|
+
|
|
67
|
+
`inheritAttrs: false` — `id`, `aria-*` and listeners land on the **trigger
|
|
68
|
+
button**, so a `Label`'s `for` reaches the focusable control.
|
|
69
|
+
|
|
70
|
+
## Anatomy
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
Popover
|
|
74
|
+
├── trigger Button outline, full width, left-aligned — a field, not a button
|
|
75
|
+
│ 📅 "22 Jul 2026" (placeholder in muted-foreground)
|
|
76
|
+
└── Calendar picking a day closes the popover
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
There's no typed text entry. A date you can type is a different control — an
|
|
80
|
+
`Input` with parsing and its own error state — and folding it in here would make
|
|
81
|
+
one component own two input models.
|
|
82
|
+
|
|
83
|
+
## Accessibility
|
|
84
|
+
|
|
85
|
+
The trigger is a real button carrying `aria-haspopup="dialog"` and
|
|
86
|
+
`aria-expanded`; the popover closes on Escape and outside click. Everything
|
|
87
|
+
inside is the calendar's.
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@surstromming/date-picker",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A field that opens a calendar to pick a date.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Evgeniy Mnatsakanov <evgeniy.mnatsakanov@gmail.com>",
|
|
7
|
+
"homepage": "https://github.com/hackteck/surstromming/tree/main/packages/date-picker#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/hackteck/surstromming.git",
|
|
11
|
+
"directory": "packages/date-picker"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/hackteck/surstromming/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"vue",
|
|
16
|
+
"vue3",
|
|
17
|
+
"component-library",
|
|
18
|
+
"design-system",
|
|
19
|
+
"ui",
|
|
20
|
+
"scss",
|
|
21
|
+
"css-modules",
|
|
22
|
+
"shadcn",
|
|
23
|
+
"date-picker"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": [
|
|
27
|
+
"**/*.scss",
|
|
28
|
+
"**/*.css"
|
|
29
|
+
],
|
|
30
|
+
"files": [
|
|
31
|
+
"src"
|
|
32
|
+
],
|
|
33
|
+
"main": "./src/index.ts",
|
|
34
|
+
"module": "./src/index.ts",
|
|
35
|
+
"types": "./src/index.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": "./src/index.ts"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@surstromming/button": "^0.1.0",
|
|
41
|
+
"@surstromming/calendar": "^0.1.0",
|
|
42
|
+
"@surstromming/design": "^0.1.0",
|
|
43
|
+
"@surstromming/icon": "^0.1.0",
|
|
44
|
+
"@surstromming/popover": "^0.1.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"vue": "^3.4.0"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Popover v-model:open="open">
|
|
3
|
+
<template #trigger>
|
|
4
|
+
<Button
|
|
5
|
+
:class="triggerClasses"
|
|
6
|
+
variant="outline"
|
|
7
|
+
:disabled="disabled"
|
|
8
|
+
aria-haspopup="dialog"
|
|
9
|
+
:aria-expanded="open"
|
|
10
|
+
v-bind="$attrs"
|
|
11
|
+
@click="toggle"
|
|
12
|
+
>
|
|
13
|
+
<Icon :icon="CalendarDays" :size="16" />
|
|
14
|
+
<span :class="$style.label">{{ label }}</span>
|
|
15
|
+
</Button>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<Calendar
|
|
19
|
+
v-model="model"
|
|
20
|
+
:min="min"
|
|
21
|
+
:max="max"
|
|
22
|
+
:is-disabled="isDisabled"
|
|
23
|
+
:week-starts-on="weekStartsOn"
|
|
24
|
+
:locale="locale"
|
|
25
|
+
@update:model-value="open = false"
|
|
26
|
+
/>
|
|
27
|
+
</Popover>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<script setup lang="ts">
|
|
31
|
+
import { computed, useCssModule } from 'vue'
|
|
32
|
+
import { Button } from '@surstromming/button'
|
|
33
|
+
import { Calendar, type WeekStart } from '@surstromming/calendar'
|
|
34
|
+
import { Icon } from '@surstromming/icon'
|
|
35
|
+
import { Popover } from '@surstromming/popover'
|
|
36
|
+
import { CalendarDays } from 'lucide'
|
|
37
|
+
|
|
38
|
+
// The trigger is the focusable control — id/aria belong on it, not the wrapper.
|
|
39
|
+
defineOptions({ inheritAttrs: false })
|
|
40
|
+
|
|
41
|
+
const props = withDefaults(
|
|
42
|
+
defineProps<{
|
|
43
|
+
placeholder?: string
|
|
44
|
+
/** How the chosen date is written on the trigger. */
|
|
45
|
+
format?: (date: Date) => string
|
|
46
|
+
min?: Date
|
|
47
|
+
max?: Date
|
|
48
|
+
isDisabled?: (date: Date) => boolean
|
|
49
|
+
weekStartsOn?: WeekStart
|
|
50
|
+
/** BCP 47 tag for the label and the calendar; omitted means the browser's. */
|
|
51
|
+
locale?: string
|
|
52
|
+
disabled?: boolean
|
|
53
|
+
}>(),
|
|
54
|
+
{ placeholder: 'Pick a date', weekStartsOn: 'monday' },
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
const model = defineModel<Date | null>({ default: null })
|
|
58
|
+
|
|
59
|
+
const open = defineModel<boolean>('open', { default: false })
|
|
60
|
+
|
|
61
|
+
const toggle = () => {
|
|
62
|
+
open.value = !open.value
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const label = computed(() => {
|
|
66
|
+
const date = model.value
|
|
67
|
+
if (!date) return props.placeholder
|
|
68
|
+
if (props.format) return props.format(date)
|
|
69
|
+
return new Intl.DateTimeFormat(props.locale, { dateStyle: 'medium' }).format(date)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const $style = useCssModule()
|
|
73
|
+
const triggerClasses = computed(() => [
|
|
74
|
+
$style.trigger,
|
|
75
|
+
{ [$style.isPlaceholder]: model.value === null },
|
|
76
|
+
])
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<style module lang="scss">
|
|
80
|
+
@use '@surstromming/design' as design;
|
|
81
|
+
|
|
82
|
+
// Left-aligned and full-width: it reads as a field, not as a button.
|
|
83
|
+
.trigger {
|
|
84
|
+
justify-content: flex-start;
|
|
85
|
+
width: 100%;
|
|
86
|
+
font-weight: 400;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.isPlaceholder {
|
|
90
|
+
color: design.color(muted-foreground);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.label {
|
|
94
|
+
overflow: hidden;
|
|
95
|
+
text-overflow: ellipsis;
|
|
96
|
+
white-space: nowrap;
|
|
97
|
+
}
|
|
98
|
+
</style>
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as DatePicker } from './DatePicker.vue'
|