1.4.9 • Published 4 years ago

adaptiv-styles v1.4.9

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

The AdaptivUI Styled Components Library 🎨

AdaptivUI is a design system built with accessability as the highest priority.

Getting Started

Installing

To install AdaptivUI to your project simply run yarn add adaptiv-ui || npm i adaptiv-ui and your ready to hook it up!

CSS overhaul and AppWrapper

AdaptivUI comes with a css file you can import that includes a nice subtle style overhaul and a normalize. Just add import "adaptiv-ui/css/main.css"; to the top of your root index.js!

AppWrapper is a powerful component that lets you set the background and fonts of your application.

Example:

import { AppWrapper } from "adaptiv-ui";

import "adaptiv-ui/css/main.css";

ReactDOM.render(
  <AppWrapper
    bg_src={
      /* This prop lets you easily set a responsive image as your background */
    }
    bg={/* Lets you set the background color of the app */}
    head_font={/* Lets you change the font of all the headers in the app */}
    font={/* Lets you can the font of everything else in the app */}
  >
    <App />
  </AppWrapper>,
  document.getElementById("root")
);

Style Props and Maps

AdaptivUI comes with some unique style props and maps that make laying out and editing you page very easily.

Style props need to be given a value and the associated

These are the props you will probably use most often. I'll break them down into catagories.

Flex-box

Props:

CSS Property NameProp NameDefault value
flex-directiondirectionrow
justify-contentjustifyflex-start
align-itemsalignnormal
align-contentcontentstretch

Example:

<Flex direction="column" align="center">
  ...
</Flex>

Style Maps:

CSS Property NameStyle PropProperty Value
flex-directioncolcolumn
flex-directionrevrowrow-reverse
flex-directionrevcolcolumn-reverse
justify-contentjc_endcenter
justify-contentjc_centerspace-between
justify-contentjc_betweenspace-around
justify-contentjc_aroundspace-evenly
justify-contentjc_evenlyflex-start
align-itemsai_centercenter
align-itemsai_startflex-start
align-itemsai_endflex-end
align-itemsai_stretchstretch
align-contentac_centercenter
align-contentac_startflex-start
align-contentac_endflex-end
align-contentac_betweenspace-between
align-contentac_aroundspace-around
align-contentac_evenlyspace-evenly
flex-directiondrapecolumn
align-itemsdrapecenter

Example:

// col changes flex-direction to column
// ai_center changes align items to center
<Flex col ai_center>...</Flex>
// drape changes flex-direction to column and align-items to center
<Flex drape>...</Flex>

Sizing and color props

Props:

CSS Property NameProp NameDefault value
heighthauto
widthwauto
width && heightsqrauto
border-radiusradius0.3rem
borderbordernone
marginm0
paddingp0
backgroundbgnone
colorcolorauto
opacityopacitynone
min-heightmin_hnone
max-widthmax_wnone
min-widthmin_wnone
max-heightmax_hnone
box-sizingbox_sizeborder-box
box-shadowshadownone
overflowoverflowhidden
font-familyfontOpen Sans
font-sizef_size1.6rem
clip-pathclipnone
background-sizebg_sizeauto
background-attachbg_sizescroll
background-positionbg_sizecenter

The square prop changes width and height at the same time!

Style Maps:

CSS Property NameStyle PropProperty Value
widthstretch100%
marginxsm1rem
marginsm2rem
marginmm3rem
marginlm4rem
marginxlm5rem
paddingxsp1rem
paddingsp2rem
paddingmp3rem
paddinglp4rem
paddingxlp5rem
font-sizexsf0.6rem
font-sizesf1rem
font-sizemf1.4rem
font-sizelf2rem
font-sizexlf3rem
box-shadowshade0 0.3rem 1rem \${theme.gray7}
box-shadowbacklight0 0.3rem 1rem \${theme.gray0}
box-sizingcboxcontent-box
box-sizinginitinitial
box-sizinginheritinherit
overflowvisiblevisible
overflowscrollscroll
overflowautoauto
text-alignta_rightright
text-alignta_leftleft
text-alignta_centercenter
text-alignta_justifyjustify
text-alignta_alljustify-all
text-alignta_startstart
text-alignta_endend
background-sizesize_lenlength
background-sizesize_covercover
background-sizesize_containcontain
background-sizesize_initialinitial
background-sizesize_inheritinherit
background-sizesize_autoauto
background-attachattach_fixfix
background-attachattach_locallocal
background-attachattach_inheritinherit
background-attachattach_initialinitial
background-attachattach_scrollscroll

New Semantic Components!

Now featuring new semantic components! Main, Section and Aside. They work much like Flex but with flex direction default to column and align items default to center. Main difference is that they break down into their sematic counterparts instead of div's.

AppWrapper:

AppWrapper is a div that is meant to wrap your app page, where you hold your routes. It's purpose is to easily change the font and background of the whole application.

Wrapper:

This should wrap every parent component. It set's min height to 100% view height, and max width is set to 100% view width. This makes flexing items around your page a dream. Default flex-direction is set to column instead of row and align-items is set to.

Text:

A text component that lets you set size, font and font weight easily.

Example:

// Bold text, font size 2rem, text align center, font Georgia
<Text bold lf ta_center font="Georgia">
  Some text here...
</Text>

Box:

Box is a div with lots of useful props. Images inside the box are set to width: 100%; height: auto; so they will size responsively. Just adjust the with of the Box to size the image.

Example:

/* Placing the image in a Box with a width of 5rem
will responsively size it to a width of 50px */
<Box w="5rem">
  <img src={`image source`} alt="alt text" >
</Box>

Box's also have a prop for background, so you can set a background color, a width and a height and you have a colored box. One thing that makes Box & FlexBox unique is that you can set shape props on them! So just by adding the prop star you turn the div into a star. See list of style maps below for full list of shape props you can choose from. You can even create your own by using the clip-path prop, clip!

Example:

<Flex w="20rem" h="10rem" jc_around ai_center shade>
  <Box star bg="red" sqr="5rem" />
  <Box message bg="green" sqr="5rem" />
  <Box octagon bg="blue" sqr="5rem" />
</Flex>

Will look like...

Shape image

I also find that Box's make good spacers, between elements!

// This puts a 20px spacer between Header, Body and Footer components
<Flex drape>
  <Header />
  <Box h="2rem" />
  <Body />
  <Box h="2rem" />
  <Footer />
</Flex>

Modal

In order to pull off a modal you're going to need 2 components: Modal and useModal. In order to make Modal work your going to need to pass it an "isActive" prop and a "toggle" prop. You can get both of these props off of useModal hook:

import { useModal } from "adaptiv-ui";

const [isActive, toggle] = useModal();

Then you can plug them into Modal and you're good to go!

Example:

import React from "react";
import { useModal, Modal, Flex, Button, Text } from "adaptiv-ui";

export default function Component() {
  const [isActive, toggle] = useModal();

  return (
    <>
      <Button onClick={toggle}>Toggle</Button>
      <Modal isActive={isActive} toggle={toggle}>
        <Flex w="40rem" h="40rem" drape>
          <Text>I'm a modal, yo!</Text>
          <Button autoFocus onClick={() => alert("Thanks for clicking me!")}>
            Click me!
          </Button>
          <Button onClick={toggle}>Close</Button>
        </Flex>
      </Modal>
    </>
  );
}

Modal image

Tool Tip

TooTip component has all the same props as Flex, but it has a special feature! After adding your element, you can place a div under it with a className of "tooltip". Whatever you put inside this "tooltip" div will be invisible until you hover over or focus on the element you nested inside your ToolTip component. In addition to the Flex props, there are a couple of extra props that ToolTip has so that you can edit your "tooltip" element and position.

tt_w: edits the width of the tooltip tt_h: edits the height of the tooltip tt_color: edits the color of the tooltip tt_bg: edits the background color of the tooltip tt_top: edits the top position of the tooltip tt_right: edits the right position of the tooltip tt_bottom: edits the bottom position of the tooltip tt_left: edits the left position of the tooltip tt_radius: edits the radius of the tooltip tt_zIndex: edits the z index of the tooltip

Example:

// using tt props to edit tool tip position and size
<ToolTip tt_left="105%" tabIndex={0} tt_w="12rem" tt_top="25%">
  {/* These two Box's make up the content that we want to add a tooltip too */}
  <Box bg={theme.primary} circle p="2rem">
    <Box sqr="2rem" window bg="white" />
  </Box>
  {/* Our "tooltip" div is the container for what we want to show in our
  tooltip on focus or hover. */}
  <div class="tooltip">
    <Text bold lf ta_center>
      Tooltip text
    </Text>
  </div>
</ToolTip>

Tooltip image

Container

Container is a component that's main purpose is to provide a background image. It also can set colors as the background but the css for images is set for responsiveness. If you need things to lay on top of a background image this is the component to use. Just wrap the content in Container and set bg_src prop to the location/URL of your image. It also has flex enabled and all sizing props. By default justify content is column and align items is center. You can change these individually to you own desire. You can also use the across props to set them to flex-start / normal respectively.

Example:

<Wrapper>
  {/* Add invert prop to make text white instead of black */}
  <Container bg_src={image} h="50vh" invert>
    <h3>Stuff...</h3>
    <h3>Stuff...</h3>
    <h3>Stuff...</h3>
  </Container>
</Wrapper>

Button:

It's a beautiful button! It has some color props to quickly and easily change the color scheme of the button.

List of color props:

  • primitive (default)
  • primary
  • secondary

Linkton:

Looks exactly like a button, but is a Link from @reach/router.

List of color props:

  • primitive (default)
  • primary
  • secondary

Example:

<Linkton to="/">Go home</Linkton>

Form:

It's a form with flex-box (direction: column, align: center by default) and some basic additional props.

Input:

A better looking input to use.

Importing adaptiv-ui css and styled components 🚀

It's highly recommended to pull in adaptiv-ui's global style overhauls, just import "adaptiv-ui/css/main.css" in your root index.js file. Feel free to check out the code to see what is under the hood! 🔥

All styled components get exported from adaptiv-ui. So all you need to do is deconstruct the component(s) you want from "adaptiv-ui".

Example:

./src/components/MyComponent

import React from "react";
import { Wrapper, Flex, Button } from "adaptiv-ui";

export default function MyComponent() {
  return (
    <Wrapper>
      <Flex drape w="80vw">
        <h2>Card Header</h2>
        <p>Card text.</p>
        <Flex>
          <Button primary>Left Button</Button>
          <Button secondary>Right Button</Button>
        </Flex>
      </Card>
    </Wrapper>
  );
}

Theme Color Variables 🖌

If you want to use the color variables in just throw in theme to your AdaptivUI import: import { theme } from "adaptiv-ui"

Example:

import React from "react";
import { Wrapper, Flex, Button, theme } from "adaptiv-ui";

export default function MyComponent() {
  return (
    <Wrapper bg={theme.gray8}>
      <Flex w="80vw" drape>
        <h2>Card Header</h2>
        <p>Card text.</p>
        <Flex>
          <Button primary>Left Button</Button>
          <Button secondary>Right Button</Button>
        </Flex>
      </Flex>
    </Wrapper>
  );
}

Check here to see the full list of my javascript theme colors.

Flex and Box Shape Props!

Flex's and Box's have unique shape props you can use to turn your div's into awesome little shapes! Highly recommend using the sqr prop to set height and width to equal size's and giving a background (bg) prop color since the default is set to none.

You can also set a custom clip path with the clip prop.

Example:

<Box sqr="5rem" bg={theme.red5} message />
CSS Property NameStyle MapProperty Value
clip-pathtrianglepolygon(50% 0%, 0% 100%, 100% 100%)
clip-pathtrapezoidpolygon(20% 0%, 80% 0%, 100% 100%, 0% 100%)
clip-pathparallelogrampolygon(25% 0%, 100% 0%, 75% 100%, 0% 100%)
clip-pathrhombuspolygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)
clip-pathpentagonpolygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%)
clip-pathhexagonpolygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%)
clip-pathheptagonpolygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%)
clip-pathoctagonpolygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%)
clip-pathnonagonpolygon(50% 0%, 83% 12%, 100% 43%, 94% 78%, 68% 100%, 32% 100%, 6% 78%, 0% 43%, 17% 12%)
clip-pathdecagonpolygon(50% 0%, 80% 10%, 100% 35%, 100% 70%, 80% 90%, 50% 100%, 20% 90%, 0% 70%, 0% 35%, 20% 10%)
clip-pathbevelpolygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%)
clip-pathrabbetpolygon(0% 15%, 15% 15%, 15% 0%, 85% 0%, 85% 15%, 100% 15%, 100% 85%, 85% 85%, 85% 100%, 15% 100%, 15% 85%, 0% 85%)
clip-patharrow_leftpolygon(0% 15%, 15% 15%, 15% 0%, 85% 0%, 85% 15%, 100% 15%, 100% 85%, 85% 85%, 85% 100%, 15% 100%, 15% 85%, 0% 85%)
clip-patharrow_rightpolygon(0% 20%, 60% 20%, 60% 0%, 100% 50%, 60% 100%, 60% 80%, 0% 80%)
clip-pathpoint_leftpolygon(25% 0%, 100% 1%, 100% 100%, 25% 100%, 0% 50%)
clip-pathpoint_rightpolygon(0% 0%, 75% 0%, 100% 50%, 75% 100%, 0% 100%)
clip-pathchevron_leftpolygon(100% 0%, 75% 50%, 100% 100%, 25% 100%, 0% 50%, 25% 0%)
clip-pathchevron_rightpolygon(75% 0%, 100% 50%, 75% 100%, 0% 100%, 25% 50%, 0% 0%)
clip-pathstarpolygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%)
clip-pathcrosspolygon(10% 25%, 35% 25%, 35% 0%, 65% 0%, 65% 25%, 90% 25%, 90% 50%, 65% 50%, 65% 100%, 35% 100%, 35% 50%, 10% 50%)
clip-pathwindowpolygon(0 40%, 40% 40%, 40% 0, 60% 0, 60% 40%, 100% 40%, 100% 60%, 60% 60%, 60% 100%, 40% 100%, 40% 60%, 0 60%)
clip-pathmessagepolygon(0% 0%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%)
clip-pathclosepolygon(20% 0%, 0% 20%, 30% 50%, 0% 80%, 20% 100%, 50% 70%, 80% 100%, 100% 80%, 70% 50%, 100% 20%, 80% 0%, 50% 30%)
clip-pathcirclecircle(50% at 50% 50%)
clip-pathellipseellipse(34% 50% at 50% 50%)