import { Style } from 'treat' import clsx from 'clsx' import { Theme } from 'treat/theme' import { Properties, SimplePseudos } from 'csstype' import * as B from 'fp-ts/boolean' import * as R from 'fp-ts/Record' import { pipe } from 'fp-ts/function' import { eqNumber } from 'fp-ts/Eq' import { ResponsiveProp } from './types' /** * Creates a Style with a single property. * * @param propertyName CSS property to which `value` will be assigned. * * @returns Treat-compatible Style to pass to `style`. */ export const styleSingleton = < TPropertyName extends keyof Properties, TValue extends string | number >( propertyName: TPropertyName, ) => (value: TValue): Style => R.singleton(propertyName, value) /** * Assigns a Style to a particular breakpoint. * * @param breakpoint Breakpoint name to which styles will be assigned. * @param theme Theme with `breakpoints` tokens. * * @returns Style assigned to the breakpoint. */ export const makeResponsive = ( breakpoint: keyof Theme['breakpoints'], theme: Theme, ) => (style: Style) => { const minWidth = Number.parseFloat(theme.breakpoints[breakpoint]) const mediaQuery = theme.mediaQueries[breakpoint] return pipe( eqNumber.equals(minWidth, 0), B.fold