// NOTE: This declaration file is now available on DefinitelyTyped: `npm install @types/xstyled__system` // As a result, this gist is no longer being maintained. /* eslint-disable @typescript-eslint/class-name-casing */ /* eslint-disable @typescript-eslint/no-explicit-any */ // Note: This is an early draft; there may be issues and a few typings use any. // Acknowledgements: // - The `styled-system` typings on DefinitelyTyped: // https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/styled-system // - The typings by RetailMeNot: // https://github.com/RetailMeNot/anchor/blob/master/src/typings.d.ts declare module "@xstyled/system" { import * as React from "react"; import * as CSS from "csstype"; import * as StyledComponents from "styled-components"; export interface StyleFunc { (...args: any[]): any; propTypes?: ReadonlyArray; } export type ThemeGetterFunc = ( props: Partial<{ theme: StyledComponents.DefaultTheme }> ) => React.ReactText; export type StyledSystemLength = string | 0 | number; export type ResponsiveValue = T | { [key: string]: T }; export type AliasKey = string; // ----- GETTERS ----- export function getColor(value: string | number): ThemeGetterFunc; export function getPx(value: string | number): ThemeGetterFunc; export function getPercent(value: string | number): ThemeGetterFunc; export function getRadius(value: string | number): ThemeGetterFunc; export function getTransition(value: string | number): ThemeGetterFunc; export function getSpace(value: string | number): ThemeGetterFunc; export function getSize(value: string | number): ThemeGetterFunc; export function getFont(value: string | number): ThemeGetterFunc; export function getLineHeight(value: string | number): ThemeGetterFunc; export function getFontWeight(value: string | number): ThemeGetterFunc; export function getLetterSpacing(value: string | number): ThemeGetterFunc; export function getFontSize(value: string | number): ThemeGetterFunc; export function getZIndex(value: string | number): ThemeGetterFunc; export function getBorder(value: string | number): ThemeGetterFunc; export function getBorderWidth(value: string | number): ThemeGetterFunc; export function getBorderStyle(value: string | number): ThemeGetterFunc; export function getShadow(value: string | number): ThemeGetterFunc; // ----- BASICS ----- export const color: StyleFunc; export interface ColorProps { readonly color?: ResponsiveValue; } export const opacity: StyleFunc; export const overflow: StyleFunc; export const transition: StyleFunc; export const basics: StyleFunc; export interface OpacityProps { readonly opacity?: ResponsiveValue; } export interface OverflowProps { readonly overflow?: ResponsiveValue; } export interface TransitionProps { readonly transition?: ResponsiveValue; } export interface BasicsProps extends OpacityProps, OverflowProps, TransitionProps {} // ----- SPACE ----- export const margin: StyleFunc; export const marginTop: StyleFunc; export const marginRight: StyleFunc; export const marginBottom: StyleFunc; export const marginLeft: StyleFunc; export const mx: StyleFunc; export const my: StyleFunc; export const padding: StyleFunc; export const paddingTop: StyleFunc; export const paddingRight: StyleFunc; export const paddingBottom: StyleFunc; export const paddingLeft: StyleFunc; export const px: StyleFunc; export const py: StyleFunc; export const space: StyleFunc; export interface MarginProps { readonly m?: ResponsiveValue>; readonly margin?: ResponsiveValue>; } export interface MarginTopProps { readonly mt?: ResponsiveValue>; readonly marginTop?: ResponsiveValue>; } export interface MarginRightProps { readonly mr?: ResponsiveValue>; readonly marginRight?: ResponsiveValue>; } export interface MarginBottomProps { readonly mb?: ResponsiveValue>; readonly marginBottom?: ResponsiveValue>; } export interface MarginLeftProps { readonly ml?: ResponsiveValue>; readonly marginLeft?: ResponsiveValue>; } export interface MarginXProps { readonly mx?: ResponsiveValue>; } export interface MarginYProps { readonly my?: ResponsiveValue>; } export interface PaddingProps { readonly p?: ResponsiveValue>; readonly padding?: ResponsiveValue>; } export interface PaddingTopProps { readonly pt?: ResponsiveValue>; readonly paddingTop?: ResponsiveValue>; } export interface PaddingRightProps { readonly pr?: ResponsiveValue>; readonly paddingRight?: ResponsiveValue>; } export interface PaddingBottomProps { readonly pb?: ResponsiveValue>; readonly paddingBottom?: ResponsiveValue< CSS.PaddingBottomProperty >; } export interface PaddingLeftProps { readonly pl?: ResponsiveValue>; readonly paddingLeft?: ResponsiveValue>; } export interface PaddingXProps { readonly px?: ResponsiveValue>; } export interface PaddingYProps { readonly py?: ResponsiveValue>; } export interface SpaceProps extends MarginProps, MarginTopProps, MarginRightProps, MarginBottomProps, MarginLeftProps, MarginXProps, MarginYProps, PaddingProps, PaddingTopProps, PaddingRightProps, PaddingBottomProps, PaddingLeftProps, PaddingXProps, PaddingYProps {} // ----- LAYOUT ----- export const display: StyleFunc; export const width: StyleFunc; export const height: StyleFunc; export const maxWidth: StyleFunc; export const maxHeight: StyleFunc; export const minWidth: StyleFunc; export const minHeight: StyleFunc; export const size: StyleFunc; export const verticalAlign: StyleFunc; export const layout: StyleFunc; export interface DisplayProps { readonly display?: ResponsiveValue; } export interface WidthProps { readonly width?: ResponsiveValue>; } export interface HeightProps { readonly height?: ResponsiveValue>; } export interface MaxWidthProps { readonly maxWidth?: ResponsiveValue>; } export interface MaxHeightProps { readonly maxHeight?: ResponsiveValue>; } export interface MinWidthProps { readonly minWidth?: ResponsiveValue>; } export interface MinHeightProps { readonly minHeight?: ResponsiveValue>; } export interface SizeProps { readonly size?: ResponsiveValue>; } export interface VerticalAlignProps { readonly verticalAlign?: ResponsiveValue< CSS.VerticalAlignProperty >; } export interface LayoutProps extends DisplayProps, WidthProps, HeightProps, MaxWidthProps, MaxHeightProps, MinWidthProps, MinHeightProps, SizeProps, VerticalAlignProps {} // ----- XGRID ----- export const col: StyleFunc; export const row: StyleFunc; export const xgrids: StyleFunc; export interface ColProps { readonly col?: ResponsiveValue; } export interface RowProps { readonly row?: ResponsiveValue; } export interface XGridProps extends ColProps, RowProps {} // ----- TYPOGRAPHY ----- export const fontFamily: StyleFunc; export const fontSize: StyleFunc; export const lineHeight: StyleFunc; export const fontWeight: StyleFunc; export const textAlign: StyleFunc; export const letterSpacing: StyleFunc; export const textTransform: StyleFunc; export const typography: StyleFunc; export interface FontFamilyProps { readonly fontFamily?: ResponsiveValue; } export interface FontSizeProps { readonly fontSize?: ResponsiveValue>; } export interface LineHeightProps { readonly lineHeight?: ResponsiveValue>; } export interface FontWeightProps { readonly fontWeight?: ResponsiveValue; // ???? } export interface TextAlignProps { readonly textAlign?: ResponsiveValue; } export interface LetterSpacingProps { readonly letterSpacing?: ResponsiveValue< CSS.LetterSpacingProperty >; } export interface TextTransformProps { readonly textTransform?: ResponsiveValue; } export interface TypographyProps extends FontFamilyProps, FontSizeProps, LineHeightProps, FontWeightProps, TextAlignProps, LetterSpacingProps, ColorProps, TextTransformProps {} // ----- FLEXBOXES ----- export const alignItems: StyleFunc; export const alignContent: StyleFunc; export const justifyContent: StyleFunc; export const justifyItems: StyleFunc; export const flexWrap: StyleFunc; export const flexBasis: StyleFunc; export const flexDirection: StyleFunc; export const flex: StyleFunc; export const justifySelf: StyleFunc; export const alignSelf: StyleFunc; export const order: StyleFunc; export const flexboxes: StyleFunc; export interface AlignItemsProps { readonly alignItems?: ResponsiveValue; } export interface AlignContentProps { readonly alignContent?: ResponsiveValue; } export interface JustifyContentProps { readonly justifyContent?: ResponsiveValue; } export interface JustifyItemsProps { readonly justifyItems?: ResponsiveValue; } export interface FlexWrapProps { readonly flexWrap?: ResponsiveValue; } export interface FlexBasisProps { readonly flexBasis?: ResponsiveValue>; } export interface FlexDirectionProps { readonly flexDirection?: ResponsiveValue; } export interface FlexProps { readonly flex?: ResponsiveValue>; } export interface JustifySelfProps { readonly justifySelf?: ResponsiveValue; } export interface AlignSelfProps { readonly alignSelf?: ResponsiveValue; } export interface OrderProps { readonly order?: ResponsiveValue; } export interface FlexboxesProps extends DisplayProps, AlignItemsProps, AlignContentProps, JustifyContentProps, JustifyItemsProps, FlexWrapProps, FlexBasisProps, FlexDirectionProps, FlexProps, JustifySelfProps, AlignSelfProps, OrderProps {} // ----- GRIDS ----- export const gridGap: StyleFunc; export const gridColumnGap: StyleFunc; export const gridRowGap: StyleFunc; export const gridColumn: StyleFunc; export const gridRow: StyleFunc; export const gridAutoFlow: StyleFunc; export const gridAutoColumns: StyleFunc; export const gridAutoRows: StyleFunc; export const gridTemplateColumns: StyleFunc; export const gridTemplateRows: StyleFunc; export const gridTemplateAreas: StyleFunc; export const gridArea: StyleFunc; export const grids: StyleFunc; export interface GridGapProps { readonly gridGap?: ResponsiveValue>; } export interface GridColumnGapProps { readonly gridColumnGap?: ResponsiveValue< CSS.GridColumnGapProperty >; } export interface GridRowGapProps { readonly gridRowGap?: ResponsiveValue>; } export interface GridColumnProps { readonly gridColumn?: ResponsiveValue; } export interface GridRowProps { readonly gridRow?: ResponsiveValue; } export interface GridAutoFlowProps { readonly gridAutoFlow?: ResponsiveValue; } export interface GridAutoColumnsProps { readonly gridAutoColumns?: ResponsiveValue< CSS.GridAutoColumnsProperty >; } export interface GridAutoRowsProps { readonly gridAutoRows?: ResponsiveValue>; } export interface GridTemplateColumnsProps { readonly gridTemplateColumns?: ResponsiveValue< CSS.GridTemplateColumnsProperty >; } export interface GridTemplateRowsProps { readonly gridTemplateRows?: ResponsiveValue< CSS.GridTemplateRowsProperty >; } export interface GridTemplateAreasProps { readonly gridTemplateAreas?: ResponsiveValue; } export interface GridAreaProps { readonly gridArea?: ResponsiveValue; } export interface GridsProps extends GridGapProps, GridColumnGapProps, GridRowGapProps, GridColumnProps, GridRowProps, GridAutoFlowProps, GridAutoColumnsProps, GridAutoRowsProps, GridTemplateColumnsProps, GridTemplateRowsProps, GridTemplateAreasProps, GridAreaProps {} // ----- BACKGROUNDS ----- export const background: StyleFunc; export const backgroundColor: StyleFunc; export const backgroundImage: StyleFunc; export const backgroundSize: StyleFunc; export const backgroundPosition: StyleFunc; export const backgroundRepeat: StyleFunc; export const backgrounds: StyleFunc; export interface BackgroundProps { readonly background?: ResponsiveValue>; } export interface BackgroundColorProps { readonly backgroundColor?: ResponsiveValue>; } export interface BackgroundImageProps { readonly backgroundImage?: ResponsiveValue; } export interface BackgroundSizeProps { readonly backgroundSize?: ResponsiveValue< CSS.BackgroundSizeProperty >; } export interface BackgroundPositionProps { readonly backgroundPosition?: ResponsiveValue< CSS.BackgroundPositionProperty >; } export interface BackgroundRepeatProps { readonly backgroundRepeat?: ResponsiveValue; } export interface BackgroundsProps extends BackgroundProps, BackgroundColorProps, BackgroundImageProps, BackgroundSizeProps, BackgroundPositionProps, BackgroundRepeatProps {} // ----- POSITIONING ----- export const position: StyleFunc; export const zIndex: StyleFunc; export const top: StyleFunc; export const right: StyleFunc; export const bottom: StyleFunc; export const left: StyleFunc; export const positioning: StyleFunc; export interface PositionProps { readonly position?: ResponsiveValue; } export interface ZIndexProps { readonly zIndex?: ResponsiveValue; } export interface TopProps { readonly top?: ResponsiveValue>; } export interface RightProps { readonly right?: ResponsiveValue>; } export interface BottomProps { readonly bottom?: ResponsiveValue>; } export interface LeftProps { readonly left?: ResponsiveValue>; } export interface PositioningProps extends PositionProps, ZIndexProps, TopProps, RightProps, BottomProps, LeftProps {} // ----- BORDERS ----- export const border: StyleFunc; export const borderTop: StyleFunc; export const borderTopColor: StyleFunc; export const borderRight: StyleFunc; export const borderRightColor: StyleFunc; export const borderBottom: StyleFunc; export const borderBottomColor: StyleFunc; export const borderLeft: StyleFunc; export const borderLeftColor: StyleFunc; export const borderColor: StyleFunc; export const borderWidth: StyleFunc; export const borderStyle: StyleFunc; export const borderRadius: StyleFunc; export const borders: StyleFunc; export interface BorderProps { readonly border?: ResponsiveValue>; } export interface BorderTopProps { readonly borderTop?: ResponsiveValue>; } export interface BorderTopColorProps { readonly borderTopColor?: ResponsiveValue; } export interface BorderRightProps { readonly borderRight?: ResponsiveValue>; } export interface BorderRightColorProps { readonly borderRightColor?: ResponsiveValue; } export interface BorderBottomProps { readonly borderBottom?: ResponsiveValue>; } export interface BorderBottomColorProps { readonly borderBottomColor?: ResponsiveValue; } export interface BorderLeftProps { readonly borderLeft?: ResponsiveValue>; } export interface BorderLeftColorProps { readonly borderLeftColor?: ResponsiveValue; } export interface BorderColorProps { readonly borderColor?: ResponsiveValue; } export interface BorderWidthProps { readonly borderWidth?: ResponsiveValue>; } export interface BorderStyleProps { readonly borderStyle?: ResponsiveValue; } export interface BorderRadiusProps { readonly borderRadius?: ResponsiveValue>; } export interface BordersProps extends BorderProps, BorderTopProps, BorderTopColorProps, BorderRightProps, BorderRightColorProps, BorderBottomProps, BorderBottomColorProps, BorderLeftProps, BorderLeftColorProps, BorderColorProps, BorderWidthProps, BorderStyleProps, BorderRadiusProps {} // ----- SHADOWS ----- export const boxShadow: StyleFunc; export const textShadow: StyleFunc; export const shadows: StyleFunc; export interface BoxShadowProps { readonly boxShadow?: ResponsiveValue; } export interface TextShadowProps { readonly textShadow?: ResponsiveValue; } export interface ShadowsProps extends BoxShadowProps, TextShadowProps {} // ----- SYSTEM ----- export const system: StyleFunc; export interface SystemProps extends BackgroundsProps, BasicsProps, BordersProps, FlexboxesProps, GridsProps, LayoutProps, PositioningProps, ShadowsProps, SpaceProps, TypographyProps, XGridProps {} // ----- COMPOSE ----- export function compose(...parsers: StyleFunc[]): StyleFunc; // ----- CREATE_SYSTEM_COMPONENT ----- export function createSystemComponent( react: typeof React, defaultComponent?: string | React.ReactNode, system?: StyleFunc ): React.ComponentType; // ----- TH ----- export function th(path: string): ThemeGetterFunc; namespace th { function color(value: string | number): ThemeGetterFunc; function px(value: string | number): ThemeGetterFunc; function percent(value: string | number): ThemeGetterFunc; function radius(value: string | number): ThemeGetterFunc; function transition(value: string | number): ThemeGetterFunc; function space(value: string | number): ThemeGetterFunc; function size(value: string | number): ThemeGetterFunc; function font(value: string | number): ThemeGetterFunc; function fontSize(value: string | number): ThemeGetterFunc; function lineHeight(value: string | number): ThemeGetterFunc; function fontWeight(value: string | number): ThemeGetterFunc; function letterSpacing(value: string | number): ThemeGetterFunc; function zIndex(value: string | number): ThemeGetterFunc; function border(value: string | number): ThemeGetterFunc; function borderWidth(value: string | number): ThemeGetterFunc; function borderStyle(value: string | number): ThemeGetterFunc; function shadow(value: string | number): ThemeGetterFunc; } // ----- STYLE ----- export function style(config: { prop: string | ReadonlyArray; cssProperty: string | ReadonlyArray; key?: any; transform?: any; themeGet?: any; }): StyleFunc; // ----- VARIANT ----- export interface VariantArgs { key?: string; default?: string | number; prop?: string; variants?: object; } export function variant({ key, default: defaultValue, prop, variants }: VariantArgs): (props: any) => any; // ----- RESPONSIVE UTILITIES ----- export interface BreakPointsRules { [key: string]: StyledComponents.BaseThemedCssFunction; } export function breakpoints( values: BreakPointsRules ): (props: any) => StyledComponents.SimpleInterpolation; export function up( key: string, rules: StyledComponents.BaseThemedCssFunction ): (props: any) => StyledComponents.SimpleInterpolation; export function down( key: string, rules: StyledComponents.BaseThemedCssFunction ): (props: any) => StyledComponents.SimpleInterpolation; export function between( lower: string, upper: string, rules: StyledComponents.BaseThemedCssFunction ): (props: any) => StyledComponents.SimpleInterpolation; }