-
Notifications
You must be signed in to change notification settings - Fork 1
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
23 changed files
with
595 additions
and
49 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
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,23 @@ | ||
import type { CalendarState } from '@react-stately/calendar' | ||
import React, { createContext, useContext } from 'react' | ||
import type { Store } from '@vtex/shoreline-store' | ||
|
||
export const CalendarContext = createContext<Store<CalendarState> | null>(null) | ||
|
||
export function CalendarProvider({ store, children }: any) { | ||
return ( | ||
<CalendarContext.Provider value={store}> | ||
{children} | ||
</CalendarContext.Provider> | ||
) | ||
} | ||
|
||
export function useCalendarContext() { | ||
const context = useContext(CalendarContext) | ||
|
||
if (!context) { | ||
throw new Error('Calendar components must be wrapped by CalendarProvider') | ||
} | ||
|
||
return context | ||
} |
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,15 @@ | ||
import { createCalendar } from '@internationalized/date' | ||
import { useCalendarState } from '@react-stately/calendar' | ||
import { Store } from '@vtex/shoreline-store' | ||
import { useMemo } from 'react' | ||
|
||
export function useCalendarStore(props: any) { | ||
const state = useCalendarState({ | ||
...props, | ||
createCalendar, | ||
}) | ||
|
||
const store = useMemo(() => new Store(state), [state]) | ||
|
||
return store | ||
} |
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 |
---|---|---|
@@ -1,52 +1,57 @@ | ||
import React from 'react' | ||
import { useCalendar } from '@react-aria/calendar' | ||
import { useCalendarState } from '@react-stately/calendar' | ||
import { createCalendar } from '@internationalized/date' | ||
import { useLocale, IconButton } from '@vtex/shoreline-components' | ||
import { IconCaretLeft, IconCaretRight } from '@vtex/shoreline-icons' | ||
import { I18nProvider } from '@react-aria/i18n' | ||
|
||
import { CalendarGrid } from './calendar-grid' | ||
import { CalendarProvider } from './calendar-provider' | ||
import { useCalendarStore } from './calendar-store' | ||
|
||
import './calendar.css' | ||
|
||
export function Calendar(props: any) { | ||
const locale = useLocale() | ||
const state = useCalendarState({ | ||
const store = useCalendarStore({ | ||
...props, | ||
locale, | ||
createCalendar, | ||
}) | ||
|
||
const { calendarProps, prevButtonProps, nextButtonProps, title } = | ||
useCalendar(props, state) | ||
|
||
console.log(prevButtonProps) | ||
useCalendar(props, store.state) | ||
|
||
return ( | ||
<div data-sl-calendar {...calendarProps}> | ||
<div data-sl-calendar-header> | ||
<IconButton | ||
label="Previous month" | ||
variant="tertiary" | ||
disabled={prevButtonProps.isDisabled} | ||
aria-label={prevButtonProps['aria-label']} | ||
onClick={prevButtonProps.onPress as any} | ||
onFocus={prevButtonProps.onFocusChange as any} | ||
> | ||
<IconCaretLeft /> | ||
</IconButton> | ||
<h2 data-sl-calendar-title>{title}</h2> | ||
<IconButton | ||
label="Next month" | ||
variant="tertiary" | ||
disabled={nextButtonProps.isDisabled} | ||
aria-label={nextButtonProps['aria-label']} | ||
onClick={nextButtonProps.onPress as any} | ||
onFocus={nextButtonProps.onFocusChange as any} | ||
> | ||
<IconCaretRight /> | ||
</IconButton> | ||
</div> | ||
<CalendarGrid state={state} /> | ||
</div> | ||
<CalendarProvider store={store}> | ||
<I18nProvider locale={locale}> | ||
<div data-sl-calendar {...calendarProps}> | ||
<div data-sl-calendar-header> | ||
<IconButton | ||
label="Previous month" | ||
variant="tertiary" | ||
disabled={prevButtonProps.isDisabled} | ||
aria-label={prevButtonProps['aria-label']} | ||
onClick={prevButtonProps.onPress as any} | ||
onFocus={prevButtonProps.onFocusChange as any} | ||
> | ||
<IconCaretLeft /> | ||
</IconButton> | ||
<h2 data-sl-calendar-title>{title}</h2> | ||
<IconButton | ||
label="Next month" | ||
variant="tertiary" | ||
disabled={nextButtonProps.isDisabled} | ||
aria-label={nextButtonProps['aria-label']} | ||
onClick={nextButtonProps.onPress as any} | ||
onFocus={nextButtonProps.onFocusChange as any} | ||
> | ||
<IconCaretRight /> | ||
</IconButton> | ||
</div> | ||
<CalendarGrid /> | ||
</div> | ||
</I18nProvider> | ||
</CalendarProvider> | ||
) | ||
} |
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,4 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. |
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,48 @@ | ||
{ | ||
"name": "@vtex/shoreline-store", | ||
"version": "0.0.0", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts" | ||
}, | ||
"./styles": "./dist/index.css" | ||
}, | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
"scripts": { | ||
"prebuild": "rm -rf dist", | ||
"dev": "tsup --watch", | ||
"build": "tsup" | ||
}, | ||
"repository": { | ||
"directory": "packages/shoreline", | ||
"type": "git", | ||
"url": "git+https://github.com/vtex/shoreline.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/vtex/shoreline/issues" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=18", | ||
"react-dom": ">=18" | ||
}, | ||
"devDependencies": { | ||
"@types/use-sync-external-store": "0.0.6" | ||
}, | ||
"dependencies": { | ||
"use-sync-external-store": "1.2.0" | ||
} | ||
} |
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,2 @@ | ||
export * from './store' | ||
export * from './use-store' |
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,31 @@ | ||
export function shallow<T>(objA: T, objB: T) { | ||
if (Object.is(objA, objB)) { | ||
return true | ||
} | ||
|
||
if ( | ||
typeof objA !== 'object' || | ||
objA === null || | ||
typeof objB !== 'object' || | ||
objB === null | ||
) { | ||
return false | ||
} | ||
|
||
const keysA = Object.keys(objA) | ||
|
||
if (keysA.length !== Object.keys(objB).length) { | ||
return false | ||
} | ||
|
||
for (let i = 0; i < keysA.length; i++) { | ||
if ( | ||
!Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) || | ||
!Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T]) | ||
) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
Oops, something went wrong.