How to use styled-system - 10 common examples

To help you get started, we’ve selected a few styled-system examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / styled-system / styled-system-tests.tsx View on Github external
};

// Test that the style definition is correct.
// https://github.com/styled-system/styled-system/blob/master/packages/styled-system/src/index.js#L108
const customFontSize = style({
    prop: 'fontSize',
    cssProperty: 'fontSize',
    alias: 'fs',
    key: 'fontSizes',
    transformValue: (n, scale) => `${get(scale, n)}px`,
    scale: [8, 16, 32],
});

// Test that the system definition is correct.
// https://github.com/styled-system/styled-system/blob/master/packages/core/src/index.js#L131
const customFontStyles = system({
    fontWeight: {
        property: 'fontWeight',
        properties: ['fontWeight'],
        scale: 'fontWeights',
        defaultScale: [200, 400, 600],
        transform: (n, scale) => get(scale, n),
    },
    letterSpacing: true,
});

const CustomFontGroup = compose(
    customFontSize,
    customFontSize,
);

const centerWithGenerics = style({
github aredotna / ervell / src / v2 / components / UI / BorderedBox / index.js View on Github external
const innerProps = compactObject(pick(rest, ...INNER_PROPS_KEYS))

  // While the input can still have configurable margins
  const outerProps = omit(rest, ...INNER_PROPS_KEYS)

  return (
    
      {children}
    
  )
}

BorderedBox.propTypes = {
  children: PropTypes.node.isRequired,
  ...space.propTypes,
  ...alignItems.propTypes,
  ...justifyContent.propTypes,
}

BorderedBox.defaultProps = {
  ...INNER_PROPS_KEYS.reduce((memo, key) => ({ ...memo, [key]: null }), {}),
}

export default BorderedBox
github aredotna / ervell / src / v2 / components / UI / BorderedBox / index.js View on Github external
// While the input can still have configurable margins
  const outerProps = omit(rest, ...INNER_PROPS_KEYS)

  return (
    
      {children}
    
  )
}

BorderedBox.propTypes = {
  children: PropTypes.node.isRequired,
  ...space.propTypes,
  ...alignItems.propTypes,
  ...justifyContent.propTypes,
}

BorderedBox.defaultProps = {
  ...INNER_PROPS_KEYS.reduce((memo, key) => ({ ...memo, [key]: null }), {}),
}

export default BorderedBox
github tresko / react-datepicker / packages / styled / src / components / Grid / Grid.tsx View on Github external
GridAutoFlowProps,
    GridAutoRowsProps,
    AlignItemsProps,
    JustifyContentProps,
    GridColumnGapProps,
    GridGapProps,
    GridRowGapProps,
    GridTemplateAreasProps,
    GridTemplateColumnsProps,
    SpaceProps,
    GridTemplateRowsProps {
  daySizeGridTemplateColumns?: number | (number | null)[] | undefined
  numberOfMonthsGridTemplateColumns?: number | (number | null)[] | undefined
}

const daySizeGridTemplateColumns = style({
  // React prop name and CSS property
  prop: 'daySizeGridTemplateColumns',
  // CSS property (if different from prop argument)
  cssProperty: 'gridTemplateColumns',
  // key for theme values
  key: 'gridTemplateColumns',
  // accessor function for transforming the value
  transformValue: n => `repeat(7, ${n}px)`,
  // add a fallback scale object or array, if theme is not present
  scale: [0, 4, 8, 16, 32],
})

const composeGridStyles = compose(
  gridAutoColumns,
  gridAutoFlow,
  gridAutoRows,
github twilio-labs / paste / packages / paste-core / utilities / text / src / index.tsx View on Github external
}

const textColor = system({
  textColor: {
    property: 'color',
    scale: 'textColors',
  },
});
const textDecoration = system({textDecoration: true});

const Text = styled.span(
  {
    margin: 0,
    padding: 0,
  },
  compose(
    space,
    display,
    verticalAlign,
    overflow,
    textDecoration,
    typography,
    textColor
  )
  // we do this because the default typings of emotion styled
  // means Text gets typed as a span, and can't be extended
  // correctly to utilise the as prop. The new HTML element attributes
  // always clash with the span html attributes. To override this,
  // we retype as a basic functional component which is easy to extend
) as React.FC
github lightspeed / flame / packages / flame / src / Core / index.tsx View on Github external
},
  borderTopRightRadius: {
    property: 'borderTopRightRadius',
    scale: 'radii',
  },
  borderBottomLeftRadius: {
    property: 'borderBottomLeftRadius',
    scale: 'radii',
  },
  borderBottomRightRadius: {
    property: 'borderBottomRightRadius',
    scale: 'radii',
  },
});

const border = compose(
  borderRadii,
  styledSystemBorder,
);

type AsProps = { as?: string };
export type FlameBoxProps = SpaceProps &
  LayoutProps &
  FlexboxProps &
  TypographyProps &
  Partial> & // Fun clashing between native color prop & styled-system color prop
  AsProps;
export const Box = styled('div')(
  compose(
    space,
    layout,
    typography,
github tresko / react-datepicker / packages / styled / src / components / Grid / Grid.tsx View on Github external
}

const daySizeGridTemplateColumns = style({
  // React prop name and CSS property
  prop: 'daySizeGridTemplateColumns',
  // CSS property (if different from prop argument)
  cssProperty: 'gridTemplateColumns',
  // key for theme values
  key: 'gridTemplateColumns',
  // accessor function for transforming the value
  transformValue: n => `repeat(7, ${n}px)`,
  // add a fallback scale object or array, if theme is not present
  scale: [0, 4, 8, 16, 32],
})

const composeGridStyles = compose(
  gridAutoColumns,
  gridAutoFlow,
  gridAutoRows,
  gridColumnGap,
  gridGap,
  gridRowGap,
  gridTemplateAreas,
  gridTemplateColumns,
  gridTemplateRows,
  alignItems,
  justifyContent,
  space,
)

const Grid = styled('div')`
  display: grid;
github BeeDesignLLC / GlutenProject.com / utils / styled.js View on Github external
// @flow
import {style, responsiveStyle} from 'styled-system'
// import PropTypes from 'prop-types'

export const gridArea = style({
  prop: 'area',
  cssProperty: 'grid-area',
})

export const gridRowGap = responsiveStyle({
  prop: 'rowGap',
  cssProperty: 'grid-row-gap',
})

export const justifySelf = responsiveStyle({
  prop: 'justifySelf',
})

export const fontStyle = responsiveStyle({
  prop: 'fontStyle',
})

// export const numberOrString = PropTypes.oneOfType([PropTypes.number, PropTypes.string])

export const text = [
  'color',
github looker-open-source / components / packages / components / src / Form / Inputs / Slider / slider_sizes.ts View on Github external
knobSize: 24,
      trackHeight: 10,
      fontSize: 'medium',
      valueSpacing: '1.65rem',
    },
    large: {
      knobSize: 32,
      trackHeight: 12,
      fontSize: 'large',
      valueSpacing: '1.9rem',
    },
  },
}
/* eslint-enable sort-keys */

export const sliderSize = variant(sliderSizeMap)
github lightspeed / flame / packages / flame / src / Button / Button.tsx View on Github external
import * as React from 'react';
import { css } from '@emotion/core';
import styled from '@emotion/styled';
import { variant as styledVariant } from 'styled-system';
import { themeGet } from '@styled-system/theme-get';
import { Merge } from 'type-fest';
import { Spinner } from '../Spinner';
import { BaseButton, ButtonHTML, ButtonSizes, BaseButtonProps } from './BaseButton';

type ColorVariants = 'neutral' | 'default' | 'primary' | 'secondary' | 'danger' | string;

const fillButtonVariants = styledVariant({
  key: 'buttonVariants.fill',
});

const fillButtonIconVariants = styledVariant({
  key: 'buttonIconVariants.fill',
});

const outlineButtonVariants = styledVariant({
  key: 'buttonVariants.outline',
});

const outlineButtonIconVariants = styledVariant({
  key: 'buttonIconVariants.outline',
});

// Until we get Icon converted to an emotion component, we'll need to rely on flameName