diff --git a/packages/canon/report.api.md b/packages/canon/report.api.md index d3f9e6fa80..0143dadcbe 100644 --- a/packages/canon/report.api.md +++ b/packages/canon/report.api.md @@ -11,14 +11,7 @@ import * as React_3 from 'react'; import { RefAttributes } from 'react'; // @public (undocumented) -export type AlignItemsProps = - | 'stretch' - | 'flex-start' - | 'center' - | 'flex-end' - | Partial< - Record - >; +export type AlignItems = 'stretch' | 'start' | 'center' | 'end'; // @public (undocumented) export type AsProps = @@ -50,12 +43,7 @@ export type Background = >; // @public (undocumented) -export type BorderRadiusProps = - | 'none' - | 'small' - | 'medium' - | 'full' - | Partial>; +export type BorderRadius = 'none' | 'small' | 'medium' | 'full'; // @public (undocumented) export const Box: ForwardRefExoticComponent< @@ -63,31 +51,25 @@ export const Box: ForwardRefExoticComponent< >; // @public (undocumented) -export interface BoxProps extends SpaceProps, ColorProps { - // (undocumented) - alignItems?: AlignItemsProps; +export interface BoxProps extends UtilityProps { // (undocumented) as?: keyof JSX.IntrinsicElements; // (undocumented) - borderRadius?: BorderRadiusProps; - // (undocumented) children?: React.ReactNode; // (undocumented) className?: string; // (undocumented) - display?: DisplayProps; - // (undocumented) - flexDirection?: FlexDirectionProps; - // (undocumented) - flexWrap?: FlexWrapProps; - // (undocumented) - justifyContent?: JustifyContentProps; - // (undocumented) style?: React.CSSProperties; } // @public (undocumented) -export type Breakpoint = keyof typeof breakpoints; +export type BoxShadow = 'small' | 'medium' | 'large'; + +// @public (undocumented) +export type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'; + +// @public (undocumented) +export type BreakpointLocal = keyof typeof breakpoints; // @public (undocumented) export const breakpoints: { @@ -209,27 +191,16 @@ export interface ContainerProps } // @public (undocumented) -export type DisplayProps = - | 'flex' - | 'none' - | 'inline' - | 'block' - | Partial>; +export type Display = 'none' | 'flex' | 'block' | 'inline'; // @public (undocumented) -export type FlexDirectionProps = - | 'row' - | 'column' - | Partial>; +export type FlexDirection = 'row' | 'column'; // @public (undocumented) -export type FlexWrapProps = - | 'wrap' - | 'nowrap' - | Partial>; +export type FlexWrap = 'wrap' | 'nowrap' | 'wrap-reverse'; // @public (undocumented) -export type Gap = Space | Partial>; +export type Gap = SpaceLocal | Partial>; // @public (undocumented) export const Grid: ForwardRefExoticComponent< @@ -332,69 +303,78 @@ export interface InlineProps extends SpaceProps, ColorProps { } // @public (undocumented) -export type JustifyContentProps = +export type JustifyContent = | 'stretch' - | 'flex-start' + | 'start' | 'center' - | 'flex-end' - | 'space-around' - | 'space-between' - | Partial< - Record< - Breakpoint, - | 'stretch' - | 'flex-start' - | 'center' - | 'flex-end' - | 'space-around' - | 'space-between' - > - >; + | 'end' + | 'around' + | 'between'; // @public (undocumented) -export type Margin = Space | Partial>; +export type Margin = SpaceLocal | Partial>; // @public (undocumented) -export type MarginBottom = Space | Partial>; +export type MarginBottom = + | SpaceLocal + | Partial>; // @public (undocumented) -export type MarginLeft = Space | Partial>; +export type MarginLeft = + | SpaceLocal + | Partial>; // @public (undocumented) -export type MarginRight = Space | Partial>; +export type MarginRight = + | SpaceLocal + | Partial>; // @public (undocumented) -export type MarginTop = Space | Partial>; +export type MarginTop = + | SpaceLocal + | Partial>; // @public (undocumented) -export type MarginX = Space | Partial>; +export type MarginX = SpaceLocal | Partial>; // @public (undocumented) -export type MarginY = Space | Partial>; +export type MarginY = SpaceLocal | Partial>; // @public (undocumented) -export type Padding = Space | Partial>; +export type Padding = SpaceLocal | Partial>; // @public (undocumented) -export type PaddingBottom = Space | Partial>; +export type PaddingBottom = + | SpaceLocal + | Partial>; // @public (undocumented) -export type PaddingLeft = Space | Partial>; +export type PaddingLeft = + | SpaceLocal + | Partial>; // @public (undocumented) -export type PaddingRight = Space | Partial>; +export type PaddingRight = + | SpaceLocal + | Partial>; // @public (undocumented) -export type PaddingTop = Space | Partial>; +export type PaddingTop = + | SpaceLocal + | Partial>; // @public (undocumented) -export type PaddingX = Space | Partial>; +export type PaddingX = + | SpaceLocal + | Partial>; // @public (undocumented) -export type PaddingY = Space | Partial>; +export type PaddingY = + | SpaceLocal + | Partial>; // @public (undocumented) -export type Space = keyof typeof space; +export type Space = 'none' | '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'; // @public (undocumented) export const space: { @@ -408,6 +388,9 @@ export const space: { '2xl': string; }; +// @public (undocumented) +export type SpaceLocal = keyof typeof space; + // @public (undocumented) export interface SpaceProps { // (undocumented) @@ -519,4 +502,52 @@ export const themes: { selector: string; }; }; + +// @public (undocumented) +export interface UtilityProps { + // (undocumented) + alignItems?: AlignItems | Partial>; + // (undocumented) + borderRadius?: BorderRadius | Partial>; + // (undocumented) + boxShadow?: BoxShadow | Partial>; + // (undocumented) + display?: Display | Partial>; + // (undocumented) + flexDirection?: FlexDirection | Partial>; + // (undocumented) + flexWrap?: FlexWrap | Partial>; + // (undocumented) + gap?: Space | Partial>; + // (undocumented) + justifyContent?: JustifyContent | Partial>; + // (undocumented) + margin?: Space | Partial>; + // (undocumented) + marginBottom?: Space | Partial>; + // (undocumented) + marginLeft?: Space | Partial>; + // (undocumented) + marginRight?: Space | Partial>; + // (undocumented) + marginTop?: Space | Partial>; + // (undocumented) + marginX?: Space | Partial>; + // (undocumented) + marginY?: Space | Partial>; + // (undocumented) + padding?: Space | Partial>; + // (undocumented) + paddingBottom?: Space | Partial>; + // (undocumented) + paddingLeft?: Space | Partial>; + // (undocumented) + paddingRight?: Space | Partial>; + // (undocumented) + paddingTop?: Space | Partial>; + // (undocumented) + paddingX?: Space | Partial>; + // (undocumented) + paddingY?: Space | Partial>; +} ``` diff --git a/packages/canon/src/components/Button/types.ts b/packages/canon/src/components/Button/types.ts index b9109a66f3..df5caa0f9f 100644 --- a/packages/canon/src/components/Button/types.ts +++ b/packages/canon/src/components/Button/types.ts @@ -14,8 +14,7 @@ * limitations under the License. */ import { IconNames } from '../Icon'; -import { Breakpoint } from '../../layout/types'; - +import type { Breakpoint } from '../../types'; /** * Properties for {@link Button} * diff --git a/packages/canon/src/components/Grid/types.ts b/packages/canon/src/components/Grid/types.ts index 87edbd75bf..097ad105e8 100644 --- a/packages/canon/src/components/Grid/types.ts +++ b/packages/canon/src/components/Grid/types.ts @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Breakpoint, ColorProps } from '../../layout/types'; +import { ColorProps } from '../../layout/types'; import { SpaceProps } from '../../layout/types'; - +import type { Breakpoint } from '../../types'; /** @public */ export type Columns = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; diff --git a/packages/canon/src/components/Heading/types.ts b/packages/canon/src/components/Heading/types.ts index fb37cf6414..7a9a44560c 100644 --- a/packages/canon/src/components/Heading/types.ts +++ b/packages/canon/src/components/Heading/types.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Breakpoint } from '../../layout/types'; +import { Breakpoint } from '../../types'; /** @public */ export interface HeadingProps { diff --git a/packages/canon/src/components/Inline/types.ts b/packages/canon/src/components/Inline/types.ts index 3d981d0d31..b4be070e8e 100644 --- a/packages/canon/src/components/Inline/types.ts +++ b/packages/canon/src/components/Inline/types.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { AsProps, Breakpoint, ColorProps } from '../../layout/types'; +import { AsProps, ColorProps } from '../../layout/types'; import { SpaceProps } from '../../layout/types'; - +import type { Breakpoint } from '../../types'; /** @public */ export interface InlineProps extends SpaceProps, ColorProps { children: React.ReactNode; diff --git a/packages/canon/src/components/Stack/types.ts b/packages/canon/src/components/Stack/types.ts index 529e92d1bd..bec5c1cb62 100644 --- a/packages/canon/src/components/Stack/types.ts +++ b/packages/canon/src/components/Stack/types.ts @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { AsProps, Breakpoint, ColorProps } from '../../layout/types'; +import { AsProps, ColorProps } from '../../layout/types'; import { SpaceProps } from '../../layout/types'; - +import type { Breakpoint } from '../../types'; /** @public */ export interface StackProps extends SpaceProps, ColorProps { children: React.ReactNode; diff --git a/packages/canon/src/components/Text/types.ts b/packages/canon/src/components/Text/types.ts index b054fdf2cf..d3232e1d67 100644 --- a/packages/canon/src/components/Text/types.ts +++ b/packages/canon/src/components/Text/types.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Breakpoint } from '../../layout/types'; +import type { Breakpoint } from '../../types'; /** @public */ export interface TextProps { diff --git a/packages/canon/src/contexts/canon.tsx b/packages/canon/src/contexts/canon.tsx index 2116d60168..a8c21e8fa9 100644 --- a/packages/canon/src/contexts/canon.tsx +++ b/packages/canon/src/contexts/canon.tsx @@ -18,21 +18,14 @@ import React, { createContext, useContext, ReactNode } from 'react'; import { IconMap, IconNames } from '../components/Icon/types'; import { defaultIcons } from '../components/Icon/icons'; import { useMediaQuery } from '../hooks/useMediaQuery'; -import { Breakpoints } from '../types'; - -const defaultBreakpoints: Breakpoints = { - xs: '0px', - sm: '640px', - md: '768px', - lg: '1024px', - xl: '1280px', - '2xl': '1536px', -}; +import type { Breakpoint } from '../types'; interface CanonContextProps { icons: IconMap; - breakpoint: keyof Breakpoints; - getResponsiveValue: (value: string | Partial) => string; + breakpoint: Breakpoint; + getResponsiveValue: ( + value: string | Partial>, + ) => string; } const CanonContext = createContext({ @@ -44,21 +37,20 @@ const CanonContext = createContext({ interface CanonProviderProps { children?: ReactNode; overrides?: Partial>; - breakpoints?: Partial; } /** @public */ export const CanonProvider = (props: CanonProviderProps) => { - const { children, overrides, breakpoints = defaultBreakpoints } = props; + const { children, overrides } = props; // Merge provided overrides with default icons const combinedIcons = { ...defaultIcons, ...overrides }; - const isBreakpointSm = useMediaQuery(`(min-width: ${breakpoints.sm})`); - const isBreakpointMd = useMediaQuery(`(min-width: ${breakpoints.md})`); - const isBreakpointLg = useMediaQuery(`(min-width: ${breakpoints.lg})`); - const isBreakpointXl = useMediaQuery(`(min-width: ${breakpoints.xl})`); - const isBreakpoint2xl = useMediaQuery(`(min-width: ${breakpoints['2xl']})`); + const isBreakpointSm = useMediaQuery(`(min-width: 640px)`); + const isBreakpointMd = useMediaQuery(`(min-width: 768px)`); + const isBreakpointLg = useMediaQuery(`(min-width: 1024px)`); + const isBreakpointXl = useMediaQuery(`(min-width: 1280px)`); + const isBreakpoint2xl = useMediaQuery(`(min-width: 1536px)`); // Determine the current breakpoint const breakpoint = (() => { @@ -70,9 +62,11 @@ export const CanonProvider = (props: CanonProviderProps) => { return 'xs'; })(); - const getResponsiveValue = (value: string | Partial) => { + const getResponsiveValue = ( + value: string | Partial>, + ) => { if (typeof value === 'object') { - const breakpointsOrder: (keyof Breakpoints)[] = [ + const breakpointsOrder: Breakpoint[] = [ 'xs', 'sm', 'md', diff --git a/packages/canon/src/index.ts b/packages/canon/src/index.ts index d6a375b8dd..e6a4fb26d3 100644 --- a/packages/canon/src/index.ts +++ b/packages/canon/src/index.ts @@ -20,9 +20,6 @@ * @packageDocumentation */ -// Layout types -export * from './layout/types'; - // Layout components export * from './components/Box'; export * from './components/Grid'; @@ -35,3 +32,7 @@ export * from './components/Button'; export * from './components/Icon'; export * from './components/Checkbox'; export * from './components/Table'; + +// Types +export * from './layout/types'; +export * from './types'; diff --git a/packages/canon/src/layout/types.ts b/packages/canon/src/layout/types.ts index c051dacb44..2d95c7a372 100644 --- a/packages/canon/src/layout/types.ts +++ b/packages/canon/src/layout/types.ts @@ -13,61 +13,82 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { breakpoints, space, themes } from './properties'; /** @public */ -export type Breakpoint = keyof typeof breakpoints; +export type BreakpointLocal = keyof typeof breakpoints; /** @public */ -export type Space = keyof typeof space; +export type SpaceLocal = keyof typeof space; /** @public */ export type Theme = keyof typeof themes; /** @public */ -export type Gap = Space | Partial>; +export type Gap = SpaceLocal | Partial>; /** @public */ -export type PaddingLeft = Space | Partial>; +export type PaddingLeft = + | SpaceLocal + | Partial>; /** @public */ -export type PaddingRight = Space | Partial>; +export type PaddingRight = + | SpaceLocal + | Partial>; /** @public */ -export type PaddingTop = Space | Partial>; +export type PaddingTop = + | SpaceLocal + | Partial>; /** @public */ -export type PaddingBottom = Space | Partial>; +export type PaddingBottom = + | SpaceLocal + | Partial>; /** @public */ -export type Padding = Space | Partial>; +export type Padding = SpaceLocal | Partial>; /** @public */ -export type PaddingX = Space | Partial>; +export type PaddingX = + | SpaceLocal + | Partial>; /** @public */ -export type PaddingY = Space | Partial>; +export type PaddingY = + | SpaceLocal + | Partial>; /** @public */ -export type MarginLeft = Space | Partial>; +export type MarginLeft = + | SpaceLocal + | Partial>; /** @public */ -export type MarginRight = Space | Partial>; +export type MarginRight = + | SpaceLocal + | Partial>; /** @public */ -export type MarginTop = Space | Partial>; +export type MarginTop = + | SpaceLocal + | Partial>; /** @public */ -export type MarginBottom = Space | Partial>; +export type MarginBottom = + | SpaceLocal + | Partial>; /** @public */ -export type Margin = Space | Partial>; +export type Margin = SpaceLocal | Partial>; /** @public */ -export type MarginX = Space | Partial>; +export type MarginX = SpaceLocal | Partial>; /** @public */ -export type MarginY = Space | Partial>; +export type MarginY = SpaceLocal | Partial>; /** @public */ export interface SpaceProps { diff --git a/packages/canon/src/types.ts b/packages/canon/src/types.ts index 6a319a6308..6ba8e455cd 100644 --- a/packages/canon/src/types.ts +++ b/packages/canon/src/types.ts @@ -13,19 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export interface Breakpoints { - xs: string; - sm: string; - md: string; - lg: string; - xl: string; - '2xl': string; -} +/** @public */ +export type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'; + +/** @public */ export type Space = 'none' | '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'; + +/** @public */ export type Display = 'none' | 'flex' | 'block' | 'inline'; + +/** @public */ export type FlexDirection = 'row' | 'column'; + +/** @public */ export type FlexWrap = 'wrap' | 'nowrap' | 'wrap-reverse'; + +/** @public */ export type JustifyContent = | 'stretch' | 'start' @@ -33,37 +37,38 @@ export type JustifyContent = | 'end' | 'around' | 'between'; + +/** @public */ export type AlignItems = 'stretch' | 'start' | 'center' | 'end'; + +/** @public */ export type BorderRadius = 'none' | 'small' | 'medium' | 'full'; + +/** @public */ export type BoxShadow = 'small' | 'medium' | 'large'; +/** @public */ export interface UtilityProps { - display?: Display | Partial>; - flexDirection?: - | FlexDirection - | Partial>; - flexWrap?: FlexWrap | Partial>; - justifyContent?: - | JustifyContent - | Partial>; - alignItems?: AlignItems | Partial>; - borderRadius?: - | BorderRadius - | Partial>; - boxShadow?: BoxShadow | Partial>; - padding?: Space | Partial>; - paddingX?: Space | Partial>; - paddingY?: Space | Partial>; - paddingLeft?: Space | Partial>; - paddingRight?: Space | Partial>; - paddingTop?: Space | Partial>; - paddingBottom?: Space | Partial>; - margin?: Space | Partial>; - marginX?: Space | Partial>; - marginY?: Space | Partial>; - marginLeft?: Space | Partial>; - marginRight?: Space | Partial>; - marginTop?: Space | Partial>; - marginBottom?: Space | Partial>; - gap?: Space | Partial>; + display?: Display | Partial>; + flexDirection?: FlexDirection | Partial>; + flexWrap?: FlexWrap | Partial>; + justifyContent?: JustifyContent | Partial>; + alignItems?: AlignItems | Partial>; + borderRadius?: BorderRadius | Partial>; + boxShadow?: BoxShadow | Partial>; + padding?: Space | Partial>; + paddingX?: Space | Partial>; + paddingY?: Space | Partial>; + paddingLeft?: Space | Partial>; + paddingRight?: Space | Partial>; + paddingTop?: Space | Partial>; + paddingBottom?: Space | Partial>; + margin?: Space | Partial>; + marginX?: Space | Partial>; + marginY?: Space | Partial>; + marginLeft?: Space | Partial>; + marginRight?: Space | Partial>; + marginTop?: Space | Partial>; + marginBottom?: Space | Partial>; + gap?: Space | Partial>; } diff --git a/packages/canon/src/utils/getClassNames.ts b/packages/canon/src/utils/getClassNames.ts index 1391590bd6..d026f3d453 100644 --- a/packages/canon/src/utils/getClassNames.ts +++ b/packages/canon/src/utils/getClassNames.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import type { Breakpoints, UtilityProps } from '../types'; +import type { Breakpoint, UtilityProps } from '../types'; const spaceMap = (type: string) => ({ none: `${type}-none`, @@ -93,7 +93,7 @@ const generateClassNames = (propName: string, propValue: any) => { classNames.push(`cu-${value}`); } else if (typeof propValue === 'object') { // If the property value is an object, map each key-value pair - Object.entries(propValue as Record).forEach( + Object.entries(propValue as Record).forEach( ([breakpoint, value]) => { const mappedValue = valueMap[propName]?.[value] || value;