Skip to content

Commit

Permalink
feat(utils): add tinyWarning and tinyInvariant
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusps committed Dec 4, 2023
1 parent 2fed95f commit f20a7c7
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/date/src/calendar/calendar-cell.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer sl-expended-components {
@layer sl-extended-components {
[data-sl-calendar-cell-button] {
width: 100%;
height: 100%;
Expand Down
5 changes: 2 additions & 3 deletions packages/date/src/calendar/calendar-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { CalendarState } from '@react-stately/calendar'
import React, { createContext, useContext } from 'react'
import type { Store } from '@vtex/shoreline-store'
import { invariant } from '@vtex/shoreline-utils'

export const CalendarContext = createContext<Store<CalendarState> | null>(null)

Expand All @@ -15,9 +16,7 @@ export function CalendarProvider({ store, children }: any) {
export function useCalendarContext() {
const context = useContext(CalendarContext)

if (!context) {
throw new Error('Calendar components must be wrapped by CalendarProvider')
}
invariant(context, 'Calendar components must be wrapped by CalendarProvider')

return context
}
6 changes: 2 additions & 4 deletions packages/date/src/calendar/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,19 @@ export function Calendar(props: CalendarProps) {
<div data-sl-calendar {...calendarProps}>
<div data-sl-calendar-header>
<IconButton
label="Previous month"
label={prevButtonProps['aria-label']}
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"
label={nextButtonProps['aria-label']}
variant="tertiary"
disabled={nextButtonProps.isDisabled}
aria-label={nextButtonProps['aria-label']}
onClick={nextButtonProps.onPress as any}
onFocus={nextButtonProps.onFocusChange as any}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/preflight.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer sl-reset, sl-base, sl-tokens, sl-components, sl-expended-components;
@layer sl-reset, sl-base, sl-tokens, sl-components, sl-extended-components;

@layer sl-reset {
*,
Expand Down
4 changes: 3 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"dependencies": {
"csstype": "3.1.2",
"deepmerge": "4.3.1",
"scule": "1.1.1"
"scule": "1.1.1",
"tiny-invariant": "1.3.1",
"tiny-warning": "1.0.3"
}
}
4 changes: 4 additions & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
splitByCase,
upperFirst,
} from './string-case'
import { invariant } from './invariant'
import { warning } from './warning'

export {
chain,
Expand Down Expand Up @@ -59,6 +61,8 @@ export {
lowerFirst,
splitByCase,
upperFirst,
invariant,
warning,
}

export * from './css-types'
Expand Down
3 changes: 3 additions & 0 deletions packages/utils/src/invariant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import invariant from 'tiny-invariant'

export { invariant }
3 changes: 3 additions & 0 deletions packages/utils/src/warning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import warning from 'tiny-warning'

export { warning }
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f20a7c7

Please sign in to comment.