diff --git a/packages/@adobe/react-spectrum/exports/Toast.ts b/packages/@adobe/react-spectrum/exports/Toast.ts index 272e4b679c3..49492f1fab3 100644 --- a/packages/@adobe/react-spectrum/exports/Toast.ts +++ b/packages/@adobe/react-spectrum/exports/Toast.ts @@ -14,4 +14,4 @@ export {ToastContainer, ToastQueue} from '../src/toast/ToastContainer'; -export type {SpectrumToastOptions, SpectrumToastContainerProps} from '../src/toast/ToastContainer'; +export type {SpectrumToastOptions, SpectrumToastContainerProps, CloseFunction} from '../src/toast/ToastContainer'; diff --git a/packages/@adobe/react-spectrum/src/toast/ToastContainer.tsx b/packages/@adobe/react-spectrum/src/toast/ToastContainer.tsx index e4f8d6086ce..e003fc9be5b 100644 --- a/packages/@adobe/react-spectrum/src/toast/ToastContainer.tsx +++ b/packages/@adobe/react-spectrum/src/toast/ToastContainer.tsx @@ -37,7 +37,7 @@ export interface SpectrumToastOptions extends ToastOptions, DOMProps { shouldCloseOnAction?: boolean } -type CloseFunction = () => void; +export type CloseFunction = () => void; function wrapInViewTransition(fn: () => void): void { if ('startViewTransition' in document) { diff --git a/packages/@internationalized/date/src/CalendarDate.ts b/packages/@internationalized/date/src/CalendarDate.ts index 6eff9f68ee1..0e5679a892b 100644 --- a/packages/@internationalized/date/src/CalendarDate.ts +++ b/packages/@internationalized/date/src/CalendarDate.ts @@ -17,6 +17,8 @@ import {dateTimeToString, dateToString, timeToString, zonedDateTimeToString} fro import {GregorianCalendar} from './calendars/GregorianCalendar'; import {toCalendarDateTime, toDate, toZoned, zonedToDate} from './conversion'; +export type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime; + function shiftArgs(args: any[]) { let calendar: Calendar = typeof args[0] === 'object' ? args.shift() diff --git a/packages/@internationalized/date/src/index.ts b/packages/@internationalized/date/src/index.ts index 5d373c842f1..39b6072f180 100644 --- a/packages/@internationalized/date/src/index.ts +++ b/packages/@internationalized/date/src/index.ts @@ -27,6 +27,7 @@ export type { CycleOptions, CycleTimeOptions } from './types'; +export type {DateValue} from './CalendarDate'; export {CalendarDate, CalendarDateTime, Time, ZonedDateTime} from './CalendarDate'; export {GregorianCalendar} from './calendars/GregorianCalendar'; diff --git a/packages/@internationalized/date/src/queries.ts b/packages/@internationalized/date/src/queries.ts index e27d50c377b..3862dc0b4eb 100644 --- a/packages/@internationalized/date/src/queries.ts +++ b/packages/@internationalized/date/src/queries.ts @@ -11,12 +11,10 @@ */ import {AnyCalendarDate, AnyTime, Calendar} from './types'; -import {CalendarDate, CalendarDateTime, ZonedDateTime} from './CalendarDate'; +import {CalendarDate, CalendarDateTime, DateValue, ZonedDateTime} from './CalendarDate'; import {fromAbsolute, toAbsolute, toCalendar, toCalendarDate} from './conversion'; import {weekStartData} from './weekStartData'; -type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime; - /** Returns whether the given dates occur on the same day, regardless of the time or calendar system. */ export function isSameDay(a: DateValue, b: DateValue): boolean { b = toCalendar(b, a.calendar); diff --git a/packages/@react-spectrum/s2/style/index.ts b/packages/@react-spectrum/s2/style/index.ts index 76f145d762b..f21fc0ea971 100644 --- a/packages/@react-spectrum/s2/style/index.ts +++ b/packages/@react-spectrum/s2/style/index.ts @@ -86,7 +86,7 @@ export const focusRing = () => ({ outlineOffset: 2 } as const); -interface IconStyle { +export interface IconStyle { size?: 'XS' | 'S' | 'M' | 'L' |'XL', color?: 'white' | 'black' | 'accent' | 'neutral' | 'negative' | 'informative' | 'positive' | 'notice' | 'gray' | 'red' | 'orange' | 'yellow' | 'chartreuse' | 'celery' | 'green' | 'seafoam' | 'cyan' | 'blue' | 'indigo' | 'purple' | 'fuchsia' | 'magenta' | 'pink' | 'turquoise' | 'cinnamon' | 'brown' | 'silver', margin?: Spacing, diff --git a/packages/@react-spectrum/s2/style/tokens.ts b/packages/@react-spectrum/s2/style/tokens.ts index 690a50f592b..8a2f0ce83ab 100644 --- a/packages/@react-spectrum/s2/style/tokens.ts +++ b/packages/@react-spectrum/s2/style/tokens.ts @@ -13,9 +13,17 @@ // package.json in this directory is not the real package.json. Lint rule not smart enough. import assert from 'assert'; // eslint-disable-next-line rulesdir/imports -import * as tokens from '@adobe/spectrum-tokens/dist/json/variables.json'; +import * as originalTokens from '@adobe/spectrum-tokens/dist/json/variables.json'; -export function getToken(name: keyof typeof tokens): string { +// This forces TSC to inline the token keys instead of leaving a dependency on it. +function keys>(v: T): Record { + return v; +} + +const tokens = keys(originalTokens); +type TokenName = keyof typeof tokens; + +export function getToken(name: TokenName): string { return (tokens[name] as any).value; } @@ -26,7 +34,7 @@ export interface ColorToken { forcedColors?: string } -export function colorToken(name: keyof typeof tokens): ColorToken | ColorRef { +export function colorToken(name: TokenName): ColorToken | ColorRef { let token = tokens[name] as typeof tokens['gray-25'] | typeof tokens['neutral-content-color-default']; if ('ref' in token) { return { @@ -43,7 +51,7 @@ export function colorToken(name: keyof typeof tokens): ColorToken | ColorRef { }; } -export function rawColorToken(name: keyof typeof tokens): string { +export function rawColorToken(name: TokenName): string { let token = tokens[name] as typeof tokens['gray-25']; return `light-dark(${token.sets.light.value}, ${token.sets.dark.value})`; } @@ -55,7 +63,7 @@ export interface ColorRef { forcedColors?: string } -export function weirdColorToken(name: keyof typeof tokens): ColorRef { +export function weirdColorToken(name: TokenName): ColorRef { let token = tokens[name] as typeof tokens['accent-background-color-default']; return { type: 'ref', @@ -66,18 +74,18 @@ export function weirdColorToken(name: keyof typeof tokens): ColorRef { type ReplaceColor = S extends `${infer S}-color-${infer N}` ? `${S}-${N}` : S; -export function colorScale(scale: S): Record>, ReturnType> { +export function colorScale(scale: S): Record>, ReturnType> { let res: any = {}; let re = new RegExp(`^${scale}-\\d+$`); for (let token in tokens) { if (re.test(token)) { - res[token.replace('-color', '')] = colorToken(token as keyof typeof tokens); + res[token.replace('-color', '')] = colorToken(token as TokenName); } } return res; } -export function simpleColorScale(scale: S): Record, string> { +export function simpleColorScale(scale: S): Record, string> { let res: any = {}; let re = new RegExp(`^${scale}-\\d+$`); for (let token in tokens) { @@ -156,10 +164,10 @@ const indexes = { }; /** Returns the index of a font token relative to font-size-100 (which is index 0). */ -export function fontSizeToken(name: keyof typeof tokens): number { +export function fontSizeToken(name: TokenName): number { let token = tokens[name] as typeof tokens['font-size-100'] | typeof tokens['heading-size-m']; if ('ref' in token) { - name = token.ref.slice(1, -1) as keyof typeof tokens; + name = token.ref.slice(1, -1) as TokenName; } let index = indexes[name]; diff --git a/packages/@react-spectrum/toast/src/index.ts b/packages/@react-spectrum/toast/src/index.ts index 272b646609b..2fd8e8dc143 100644 --- a/packages/@react-spectrum/toast/src/index.ts +++ b/packages/@react-spectrum/toast/src/index.ts @@ -14,4 +14,4 @@ export {ToastContainer, ToastQueue} from '@adobe/react-spectrum/Toast'; -export type {SpectrumToastOptions, SpectrumToastContainerProps} from '@adobe/react-spectrum/Toast'; +export type {SpectrumToastOptions, SpectrumToastContainerProps, CloseFunction} from '@adobe/react-spectrum/Toast'; diff --git a/packages/@react-stately/data/src/index.ts b/packages/@react-stately/data/src/index.ts index cc53c3e0edf..68cac432e0f 100644 --- a/packages/@react-stately/data/src/index.ts +++ b/packages/@react-stately/data/src/index.ts @@ -15,5 +15,5 @@ export {useAsyncList} from 'react-stately/useAsyncList'; export {useTreeData} from 'react-stately/useTreeData'; export {useListData} from 'react-stately/useListData'; export type {ListOptions, ListData} from 'react-stately/useListData'; -export type {AsyncListOptions, AsyncListData} from 'react-stately/useAsyncList'; +export type {AsyncListOptions, AsyncListData, AsyncListLoadFunction, AsyncListLoadOptions, AsyncListStateUpdate} from 'react-stately/useAsyncList'; export type {TreeOptions, TreeData} from 'react-stately/useTreeData'; diff --git a/packages/react-stately/exports/useAsyncList.ts b/packages/react-stately/exports/useAsyncList.ts index 44f2b577478..177f132a2be 100644 --- a/packages/react-stately/exports/useAsyncList.ts +++ b/packages/react-stately/exports/useAsyncList.ts @@ -11,4 +11,4 @@ */ export {useAsyncList} from '../src/data/useAsyncList'; -export type {AsyncListOptions, AsyncListData} from '../src/data/useAsyncList'; +export type {AsyncListOptions, AsyncListData, AsyncListLoadFunction, AsyncListLoadOptions, AsyncListStateUpdate} from '../src/data/useAsyncList'; diff --git a/packages/react-stately/src/data/useAsyncList.ts b/packages/react-stately/src/data/useAsyncList.ts index c63ff8713b4..2d81599a1e2 100644 --- a/packages/react-stately/src/data/useAsyncList.ts +++ b/packages/react-stately/src/data/useAsyncList.ts @@ -32,9 +32,9 @@ export interface AsyncListOptions { sort?: AsyncListLoadFunction & {sortDescriptor: SortDescriptor}> } -type AsyncListLoadFunction = AsyncListLoadOptions> = (state: S) => AsyncListStateUpdate | Promise>; +export type AsyncListLoadFunction = AsyncListLoadOptions> = (state: S) => AsyncListStateUpdate | Promise>; -interface AsyncListLoadOptions { +export interface AsyncListLoadOptions { /** The items currently in the list. */ items: T[], /** The keys of the currently selected items in the list. */ @@ -51,7 +51,7 @@ interface AsyncListLoadOptions { loadingState?: LoadingState } -interface AsyncListStateUpdate { +export interface AsyncListStateUpdate { /** The new items to append to the list. */ items: Iterable, /** The keys to add to the selection. */