From 60ddf41e74ebc86ec085524d69c986f51289c9c6 Mon Sep 17 00:00:00 2001 From: hywax Date: Tue, 12 Nov 2024 18:37:41 +0500 Subject: [PATCH 01/30] feat(calendar): implement component --- docs/content/3.components/calendar.md | 32 ++++++++++++++++ playground/app/pages/components/calendar.vue | 5 +++ src/runtime/components/Calendar.vue | 39 ++++++++++++++++++++ src/runtime/types/index.ts | 1 + src/theme/calendar.ts | 7 ++++ src/theme/index.ts | 1 + test/components/Calendar.spec.ts | 17 +++++++++ 7 files changed, 102 insertions(+) create mode 100644 docs/content/3.components/calendar.md create mode 100644 playground/app/pages/components/calendar.vue create mode 100644 src/runtime/components/Calendar.vue create mode 100644 src/theme/calendar.ts create mode 100644 test/components/Calendar.spec.ts diff --git a/docs/content/3.components/calendar.md b/docs/content/3.components/calendar.md new file mode 100644 index 0000000000..301407d4a1 --- /dev/null +++ b/docs/content/3.components/calendar.md @@ -0,0 +1,32 @@ +--- +description: +links: + - label: Calendar + icon: i-custom-radix-vue + to: https://www.radix-vue.com/components/calendar.html + - label: GitHub + icon: i-simple-icons-github + to: https://github.com/nuxt/ui/tree/v3/src/runtime/components/Calendar.vue +--- + +## Usage + +## Examples + +## API + +### Props + +:component-props + +### Slots + +:component-slots + +### Emits + +:component-emits + +## Theme + +:component-theme diff --git a/playground/app/pages/components/calendar.vue b/playground/app/pages/components/calendar.vue new file mode 100644 index 0000000000..689a2358aa --- /dev/null +++ b/playground/app/pages/components/calendar.vue @@ -0,0 +1,5 @@ + diff --git a/src/runtime/components/Calendar.vue b/src/runtime/components/Calendar.vue new file mode 100644 index 0000000000..722b3400d5 --- /dev/null +++ b/src/runtime/components/Calendar.vue @@ -0,0 +1,39 @@ + + + + + diff --git a/src/runtime/types/index.ts b/src/runtime/types/index.ts index 5a255078d5..0153fa2273 100644 --- a/src/runtime/types/index.ts +++ b/src/runtime/types/index.ts @@ -6,6 +6,7 @@ export * from '../components/AvatarGroup.vue' export * from '../components/Badge.vue' export * from '../components/Breadcrumb.vue' export * from '../components/Button.vue' +export * from '../components/Calendar.vue' export * from '../components/Card.vue' export * from '../components/Carousel.vue' export * from '../components/Checkbox.vue' diff --git a/src/theme/calendar.ts b/src/theme/calendar.ts new file mode 100644 index 0000000000..fc5e12fb22 --- /dev/null +++ b/src/theme/calendar.ts @@ -0,0 +1,7 @@ +export default { + slots: { + root: '' + }, + variants: {}, + compoundVariants: [] +} diff --git a/src/theme/index.ts b/src/theme/index.ts index d02a54c358..d11b2a13da 100644 --- a/src/theme/index.ts +++ b/src/theme/index.ts @@ -6,6 +6,7 @@ export { default as badge } from './badge' export { default as breadcrumb } from './breadcrumb' export { default as button } from './button' export { default as buttonGroup } from './button-group' +export { default as calendar } from './calendar' export { default as card } from './card' export { default as carousel } from './carousel' export { default as checkbox } from './checkbox' diff --git a/test/components/Calendar.spec.ts b/test/components/Calendar.spec.ts new file mode 100644 index 0000000000..d5dd06469f --- /dev/null +++ b/test/components/Calendar.spec.ts @@ -0,0 +1,17 @@ +import { describe, it, expect } from 'vitest' +import Calendar, { type CalendarProps, type CalendarSlots } from '../../src/runtime/components/Calendar.vue' +import ComponentRender from '../component-render' + +describe('Calendar', () => { + it.each([ + // Props + ['with as', { props: { as: 'div' } }], + ['with class', { props: { class: '' } }], + ['with ui', { props: { ui: {} } }], + // Slots + ['with default slot', { slots: { default: () => 'Default slot' } }] + ])('renders %s correctly', async (nameOrHtml: string, options: { props?: CalendarProps, slots?: Partial }) => { + const html = await ComponentRender(nameOrHtml, options, Calendar) + expect(html).toMatchSnapshot() + }) +}) From 8edd8f2b32888d8460d3292f3f2105c40fd4afb9 Mon Sep 17 00:00:00 2001 From: hywax Date: Wed, 13 Nov 2024 15:19:11 +0500 Subject: [PATCH 02/30] feat(Calendar): base struct --- package.json | 1 + playground/app/app.vue | 1 + playground/app/pages/components/calendar.vue | 31 ++++++- pnpm-lock.yaml | 3 + src/runtime/components/Calendar.vue | 94 ++++++++++++++++++-- src/theme/calendar.ts | 48 ++++++++-- 6 files changed, 161 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 6ab51705b7..079e3fcbca 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ }, "dependencies": { "@iconify/vue": "^4.1.2", + "@internationalized/date": "^3.5.6", "@nuxt/devtools-kit": "^1.6.0", "@nuxt/fonts": "^0.10.2", "@nuxt/icon": "^1.7.2", diff --git a/playground/app/app.vue b/playground/app/app.vue index 88d97b594e..d56812c0b7 100644 --- a/playground/app/app.vue +++ b/playground/app/app.vue @@ -13,6 +13,7 @@ const components = [ 'button', 'button-group', 'card', + 'calendar', 'carousel', 'checkbox', 'chip', diff --git a/playground/app/pages/components/calendar.vue b/playground/app/pages/components/calendar.vue index 689a2358aa..557205dffd 100644 --- a/playground/app/pages/components/calendar.vue +++ b/playground/app/pages/components/calendar.vue @@ -1,5 +1,32 @@ + + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dc7091cf46..552a842fe5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: '@iconify/vue': specifier: ^4.1.2 version: 4.1.2(vue@3.5.12(typescript@5.6.3)) + '@internationalized/date': + specifier: ^3.5.6 + version: 3.5.6 '@nuxt/devtools-kit': specifier: ^1.6.0 version: 1.6.0(magicast@0.3.5)(rollup@4.25.0)(vite@5.4.11(@types/node@22.9.0)(lightningcss@1.28.1)(terser@5.36.0)) diff --git a/src/runtime/components/Calendar.vue b/src/runtime/components/Calendar.vue index 722b3400d5..4618c122f7 100644 --- a/src/runtime/components/Calendar.vue +++ b/src/runtime/components/Calendar.vue @@ -1,6 +1,7 @@ diff --git a/src/theme/calendar.ts b/src/theme/calendar.ts index fc5e12fb22..91c187185d 100644 --- a/src/theme/calendar.ts +++ b/src/theme/calendar.ts @@ -1,7 +1,43 @@ -export default { - slots: { - root: '' - }, - variants: {}, - compoundVariants: [] +import type { ModuleOptions } from '../module' + +export default (options: Required) => { + return { + slots: { + root: 'rounded-[calc(var(--ui-radius)*1.5)] p-4', + header: 'flex items-center justify-between', + body: 'flex flex-col space-y-4 pt-4 sm:flex-row sm:space-x-4 sm:space-y-0', + heading: 'text-sm font-medium', + grid: 'w-full border-collapse select-none space-y-1', + gridRow: 'grid grid-cols-7', + gridWeekDaysRow: 'mb-1 grid w-full grid-cols-7', + gridBody: 'grid', + headCell: 'rounded-md text-xs text-red', + cell: 'relative text-center text-sm', + cellTrigger: 'relative flex items-center justify-center rounded-full whitespace-nowrap text-sm font-normal w-8 h-8 outline-none focus:shadow-[0_0_0_2px] focus:shadow-black data-[disabled]:text-black/30 data-[selected]:!bg-green10 data-[selected]:text-white hover:bg-green5 data-[highlighted]:bg-green5 data-[unavailable]:pointer-events-none data-[unavailable]:text-black/30 data-[unavailable]:line-through before:absolute before:top-[5px] before:hidden before:rounded-full before:w-1 before:h-1 before:bg-white data-[today]:before:block data-[today]:before:bg-green9', + paginationButton: 'inline-flex items-center cursor-pointer justify-center rounded-[9px] bg-transparent w-8 h-8 hover:bg-black hover:text-white active:scale-98 active:transition-all focus:shadow-[0_0_0_2px] focus:shadow-black', + paginationIcon: 'w-6 h-6' + }, + variants: { + color: { + ...Object.fromEntries((options.theme.colors || []).map((color: string) => [color, ''])), + neutral: '' + }, + size: { + xs: {}, + sm: {}, + md: {}, + lg: {}, + xl: {} + } + }, + compoundVariants: [ + ...(options.theme.colors || []).map((color: string) => ({ + color + })) + ], + defaultVariants: { + size: 'md', + color: 'primary' + } + } } From fc9d69bafbd2f1eb8837dde6f8834db317420f30 Mon Sep 17 00:00:00 2001 From: hywax Date: Wed, 13 Nov 2024 16:45:19 +0500 Subject: [PATCH 03/30] feat(Calendar): style --- playground/app/pages/components/calendar.vue | 6 +-- src/runtime/components/Calendar.vue | 12 ++--- src/theme/calendar.ts | 47 +++++++++++++++----- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/playground/app/pages/components/calendar.vue b/playground/app/pages/components/calendar.vue index 557205dffd..60d5c9e19f 100644 --- a/playground/app/pages/components/calendar.vue +++ b/playground/app/pages/components/calendar.vue @@ -8,11 +8,11 @@ const value = ref(new Date())