1.0.0-alpha.1 • Published 5 years ago

flokit v1.0.0-alpha.1

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Getting Started

Install

With npm.

npm install --save flokit

Or with yarn.

yarn add flokit

Usage

Import components directly from flokit to build and/or compose your UI or design system.

import { Flex } from 'flokit'

<Flex
  width={1}
  height={1}
  alignItems='center'
  justifyContent='center'
>
  I'm a flexbox
</Flex>

Props

Flokit is built with styled-system for theamable and responsive style props. So go check their docs if you are not familiar with it yet.

Strings

Strings values are parsed to raw CSS values, you can use it to set non numerical property values, or to use custom units for numerical values, as rem or em. You can also use strings for setting values defined in the theme object, as for color values.

// picks the value defined in `theme.colors['blue']`
<Box color='blue' />

// picks up a nested color value using dot notation
// `theme.colors['gray'][0]`
<Box color='gray.0' />

// raw CSS color value
<Box color='#f00' />

// width `'2em'`
<Box width='2em' />

// sets margin `'auto'`
<Box m='auto' />

// sets margin `'16rem'`
<Box m='16rem' />

Numbers

You can use numbers as props in several ways to define property values.

  • For scale props as const spaces = [0, 4, 8, 16, 32] for defining margin and padding, you can use numbers from 0 to the length of the scale.
// sets margin value of `theme.space[1]`
<Box m={1} />

// sets a margin value of `16px` since it's greater than `theme.space.length`
<Box m={16} />
  • For percentange values as width and height you can use numbers between 0-1. Numbers greater than 1 are transformed into raw pixel values.
// width `33.3%`
<Box width={1/3} />

// width `50%`
<Box width={1/2} />

// width `100%`
<Box width={1} />

// width `256px`
<Box width={256} />

Arrays

You can use a shorthand array syntax to define responsive width, height, margin, padding, font-size and a lot of other properties.

<Box width={[1, 1/2, 1/4]} />

This will map your array of values into mobile-first media queries, giving you the following:

.Box {
  width: 100%;
}

@media screen and (min-width: 40em) {
  .Box {
    width: 50%;
  }
}

@media screen and (min-width: 52em) {
  .Box {
    width: 25%;
  }
}

Components

Box

Primitive box-model component. Used as the base for all other components.

import { Box } from 'flokit'

<Box>
  I'm a box
</Box>

Props

PropCSS PropertyTypeTheme
positionpositionstring|arraynone
zIndexz-indexstring|arrayzIndices
toptopstring|arraynone
rightrightstring|arraynone
bottombottomstring|arraynone
leftleftstring|arraynone
displaydisplaystring|arraynone
widthwidthstring|number|arraysizes
heightheightstring|number|arraysizes
minWidthmin-widthstring|number|arraysizes
maxWidthmax-widthstring|number|arraysizes
minHeightmin-heightstring|number|arraysizes
maxHeightmax-heightstring|number|arraysizes
sizewidth & heightstring|number|arraysizes
verticalAlignvertical-alignstring|arraynone
overflowoverflowstring|arraynone
m|marginmarginstring|number|arrayspace
mt|marginTopmargin-topstring|number|arrayspace
mr|marginRightmargin-rightstring|number|arrayspace
mb|marginBottommargin-bottomstring|number|arrayspace
ml|marginLeftmargin-leftstring|number|arrayspace
mx|marginXmargin-left & margin-rightstring|number|arrayspace
my|marginYmargin-top & margin-bottomstring|number|arrayspace
p|paddingpaddingstring|number|arrayspace
pt|paddingToppadding-topstring|number|arrayspace
pr|paddingRightpadding-rightstring|number|arrayspace
pb|paddingBottompadding-bottomstring|number|arrayspace
pl|paddingLeftpadding-leftstring|number|arrayspace
pxpadding-left & padding-rightstring|number|arrayspace
pypadding-top & padding-bottomstring|number|arrayspace
backgroundbackgroundstring|arraynone
backgroundImagebackground-imagestring|arraynone
backgroundSizebackground-sizestring|arraynone
backgroundPositionbackground-positionstring|arraynone
backgroundRepeatbackground-repeatstring|arraynone
borderborderstring|arrayborders
borderWidthborder-widthstring|arrayborderWidths
borderStyleborder-stylestring|arrayborderStyles
borderColorborder-colorstring|arraycolors
borderRadiusborder-radiusstring|number|arrayradii
borderTopborder-topstring|arrayborders
borderRightborder-rightstring|arrayborders
borderBottomborder-bottomstring|arrayborders
borderLeftborder-leftstring|arrayborders
textShadowtext-shadowstring|arrayshadows
boxShadowbox-shadowstring|arrayshadows
colorcolorstring|arraycolors
bg|backgroundColorbackground-colorstring|arraycolors
opacityopacitystring|arraynone
flexflexstring|arraynone
flex-growflex-growstring|arraynone
flex-shrinkflex-shrinkstring|arraynone
flex-basisflex-basisstring|arraynone
justifySelfjustify-selfstring|arraynone
alignSelfalign-selfstring|arraynone
orderorderstring|arraynone

Flex

Primitive flexbox component. Extends Box.

import { Flex } from 'flokit'

<Flex alignItems='center'>
  I'm a flexbox
</Flex>

Props

PropCSS PropertyTypeTheme
alignItemsalign-itemsstring|arraynone
alignContentalign-contentstring|arraynone
justifyItemsjustify-itemsstring|arraynone
justifyContentjustify-contentstring|arraynone
flexWrapflex-wrapstring|arraynone
flexDirectionflex-directionstring|arraynone

Text

Primitive text component. Extends Box.

import { Text } from 'flokit'

<Text alignItems='center'>
  I'm a text
</Text>

Props

PropCSS PropertyTypeTheme
fontFamilyfont-familystring|number|arrayfonts
fontSizefont-sizestring|number|arrayfontSizes
fontWeightfont-weightstring|number|arrayfontWeights
lineHeightline-heightstring|number|arraylineHeights
letterSpacingletter-spacingstring|number|arrayletterSpacings
fontStylefont-stylestring|number|arraynone
textAligntext-alignstring|number|arraynone
textTransformtext-transformstring|number|arraynone

Heading

Primitive text component for headings. Extends Text.

import { Heading } from 'flokit'

<Heading alignItems='center'>
  I'm a heading
</Heading>

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT License © Iago Dahlem