arrow-left

Only this pageAll pages
gitbookPowered by GitBook
1 of 9

Axis

Loading...

Components

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Introduction

Axis is a theme-based component library that is fully responsive and extensible.

hashtag
Installation

Use npm or yarn:

$ yarn add @theise3107/axis
circle-info

Axis supports SSR by default, no configuration needed

Use ThemeProvider to wrapper all of the styled-components to provide the theme as prop:

circle-info

Providing your theme is optional but it is highly recommended to extend the default theme as per your style

Use styled-components in your pages

app.js
import React from 'react'
import { ThemeProvider } from '@therise3107/axis'

import theme from 'styles/theme'

const app = ({ children }) => (
  <ThemeProvider theme={theme}>
    {children}
  </ThemeProvider>
)
import React from 'react'
import { Row, Column, Container, Heading, Text } from '@therise3107/axis'

const home = () => (
    <Container>
        <Row>
            <Column>
                <Heading>Cats 🐱</Heading>
                <Text>Cats are planning global invasion!</Text>
            </Column>
            
            <Column>
                <Heading>Dogs 🐶</Heading>
                <Text>Dogs are here to the rescue!</Text>
            </Column>
        </Row>
    </Container>
)

Flex

Flex is wrapper for your items which needs to be placed as flexible boxes. It is used to group multiple items both vertically and horizontally

hashtag
Usage

Simply import Flex from axis:

circle-info

Flex component is theme agnostic, it is purely prop based

hashtag
Concept

Flex uses x-axis and y-axis to lay the flex-items, by default the direction of flex is row. We use the concept of main-axis and cross-axis

  • main-axis is the axis around which flex is laying it items, by default row

  • cross-axis is the perpendicular axis to the main axis, by default column

This means changing flex-direction should also reverse the main-axis to cross-axis and vice versa, for this reason, we first need to define the main-axis and cross-axis

circle-info

If we reverse the flex-direction, then crossAxis and mainAxis are also changed

hashtag
API Reference

circle-info

If we pass reversed to Flex, align and justify are interchanged as well

hashtag
Further reading

You can also read about Aligning of items in Flex at MDN

home.js
import React from 'react'
import { Flex, Text } from '@therise3107/axis'

const home = () => (
    <Flex>
        <Text>Sample text 1</Text>
        <Text>Sample text 2</Text>
    </Flex>
)

✅

end

✅

✅

stretch

✅

✅

spaceBetween

-

✅

spaceAround

-

✅

spaceEvenly

-

✅

stretch

-

✅

Number

Property

crossAxis

mainAxis

initial

✅

✅

top

✅

✅

bottom

✅

✅

center

Prop

Type

align

Object.keys(crossAxis)

justify

Object.keys(mainAxis)

height

String or Number

reversed

Bool

width

String or Number

herearrow-up-right

✅

zIndex

Row

Rows are the used as the wrapper to the Column, they adjust the padding provided by Container by adding row gap and column gap.

hashtag
Usage

Usage of Row is simple, never use them alone, always use them to group the Columns.

circle-exclamation

Row should never be used alone, always use them to group the Columns.

hashtag
API reference

For screen size (sm) ≥ 576px row has row gap of 2 * {theme.variables.gutter}rem and column gap {theme.variable.gutter}rem

For screen size (xs) < 576px row has row gap of 1 * {theme.variables.gutter}rem and column gap 0.5 * {theme.variable.gutter}rem

You can change the gutter in your theme file just note the same gutter is used Button, Container and Row

home.js
import React from 'react'
import { Row, Column, Container, Heading, Text } from '@therise3107/axis'

const home = () => (
    <Container>
        <Row>
            <Column>
                <Heading>Cats 🐱</Heading>
                <Text>Cats are planning global invasion!</Text>
            </Column>
            
            <Column>
                <Heading>Dogs 🐶</Heading>
                <Text>Dogs are here to the rescue!</Text>
            </Column>
        </Row>
    </Container>
)

Column

Columns are used to vertically place the content across row(s)

hashtag
Usage

Using Column is very simple just use them inside your Row(s) to place your content, every Column has fixed minimum width of 200px and maximum width of the parent row.

Simple usage

circle-exclamation

Columns should always be used as immediate child to Rows

Props, following will only be applied when the screen size matches their respective size:

circle-info

Column uses minimum width media query, this means the size of the smallest screen should by default apply to all the larger screens unless explicitly specified

This means <Column sm={1} md={1} lg={1} /> is equivalent to <Column />

Compound usage

  • The above code will reserve 2 / 3 space for first column, 1 / 3 for second column for screen size ≥ md+

  • The above code will reserve 1 / 2 space for first column, 2 / 3 for second column for sm < screen size < md

Typography

Typography is the way to represent your content as much as clear as possible with the help of certain uniform rules.

hashtag
Introduction

While typography is much easier to state but it is sometimes complicated to follow along. Establishing a good and clear typography is two way process, first your designs should be clear and well visible, second how we have implemented those design in our code with the rules which we define based on the designs.

We are mostly going to talk how we can work on the later part, i.e defining the rules which can be extended and uniformly applied to all of our content. The first step is to differentiate various content types, like what is heading, text and link and how they are used together. The next step is to draw the common styling analogy, like what are the typographies which are using same font-family. In next step we create a grouping of these common styling and name them appropriately for example

  • Typography primary for main text like heading, texts

  • Typography secondary for auxiliaries like font inside button

  • Typography code for code snippets

We can continue the list as per our design, but the main concept is every code snippet should use the code typography, same for others as well. This is encouraged to not mix styled-components with naked <p> tags.

Don't worry if this doesn't make much sense right now, the key concept is we use a named property for classifying different texts in our app.

Typography in Axis is provided via three Components:

  • Heading

  • Text

  • Link

hashtag
API Reference

In order to use our styled-components, Axis uses the same theme properties across all kind of typographical components. We will need to extend our theme, prior to using the components, something like this:

triangle-exclamation

Please make sure to export fontSize,fontWeight,lineHeight,letterSpacing and typography from your theme file, all of these properties are later used inside components to ensure uniformity.

triangle-exclamation

Please make sure to use the same key, heading and primaryin your typography, Heading and Text uses them as defaultProps.

We are going to use the above file for explaining our components

home.js
import React from 'react'
import { Row, Column, Container, Heading, Text } from '@therise3107/axis'

const home = () => (
    <Container>
        <Row>
            <Column>
                <Heading>Cats 🐱</Heading>
                <Text>Cats are planning global invasion!</Text>
            </Column>
            
            <Column>
                <Heading>Dogs 🐶</Heading>
                <Text>Dogs are here to the rescue!</Text>
            </Column>
        </Row>
    </Container>
)

number

≥ 0

lg

≥ 992px

number

≥ 0

xl

≥ 1200px

number

≥ 0

xxl

1400px

number

≥ 0

Please note, size xs is always 1, so every upcoming parent will also get size 1 this means when the screen-size is <576px the screen will be divided equally and if the content takes more than 200px then the second column will be pushed to the next row

  • Another thing to note is, we have to explicitly give md={1} in second column, this means very size after md will all have size = 1

  • Props

    Size

    Type

    value

    xs

    < 576px

    number

    fixed 1

    sm

    ≥ 576px

    number

    ≥ 0

    md

    ≥ 768px

    home.js
    import React from 'react'
    import { Row, Column, Container, Heading, Text } from '@therise3107/axis'
    
    const home = () => (
        <Container>
            <Row>
                <Column md={2}>
                    <Heading>Cats 🐱</Heading>
                    <Text>Cats are planning global invasion!</Text>
                </Column>
    
                <Column sm={2} md={1}>
                    <Heading>Dogs 🐶</Heading>
                    <Text>Dogs are here to the rescue!</Text>
                </Column>
            </Row>
        </Container>
    )
    customTheme.js
    const fontSize = {
    	xxl: '2.5rem',
    	xl: '2rem',
    	xlg: '1.8rem',
    	lg: '1.6rem',
    	md: '1.4rem',
    	sm: '1.2rem',
    	xsm: '1rem',
    	xs: '0.8rem',
    	xxs: '0.7rem'
    }
    
    const fontWeight = {
      light: 300,
      normal: 400,
    	bold: 500,
    	bolder: 700
    }
    
    const lineHeight = {
      comfort: '1.6em',
      cozy: '1.4em',
      compact: '1em',
    }
    
    const letterSpacing = {
    	comfort: '1.6em',
      cozy: '1.4em',
      compact: '1em',
    }
    
    const fonts = {
    	primaryFont: 'Avenir, sans-serif',
    	secondaryFont: 'open sans'
    }
    
    const typography = {
    	heading: {
    		fontFamily: fonts.primaryFont,
    		fontSize: fontSize.lg,
    		fontWeight: fontWeight.normal,
    		lineHeight: 1.2
    	},
    	primary: {
    		fontFamily: fonts.primaryFont,
    		fontSize: fontSize.xsm,
    		fontWeight: fontWeight.normal,
    		lineHeight: 1.2
    	},
    }
    
    
    // ...other properties
    
    export default Object.freeze({
    // ...other properties
    	fontSize,
      fontWeight,
    	lineHeight,
    	letterSpacing,
    	typography,
    })

    Layout

    Responsive grid components which provides uniformity across different devices and screen sizes.

    The Axis layout system used Grid based layout that consists of following:

    • Containerarrow-up-right

    • Rowarrow-up-right

    Layout in Axis is responsive that means, we don't need to have fixed vertical Columns, we simply use the Column inside the Row and our content automatically gets evenly places without breaking the responsiveness by auto adjusting as we place more column.

    Every Column has minimum width of 200px to ensure your content shifts to the next row if there is not enough space on mobile

    • Containers are used as a wrapper to your content this should remain the same across your website for consistency and uniformity.

    • Row should have Container as a parent and they are used as a wrapper to columns

    • Columns will auto adjust your content by placing overflowing content to next row

    Each column uses equal width in row unless specified, i.e two immediate columns of row will have equal width equal to the width of row / number of columns

  • Use breakpoint props in Column to place your content based on different screen sizes

  • Columnarrow-up-right

    Container

    Containers are used to wrap your content to encourage consistency and provides default padding to your content:

    hashtag
    Usage

    circle-info

    Containers can be used once at the top level of your application

    Containers are fully responsive, they will auto-adjust based on the screen size. Below is the breakpoints table used for the maximum width of Containers:

    Containers can also be fluid just use them as <Container fluid>

    hashtag
    API Reference

    For screen size (sm) ≥ 576px Container has horizontal padding of {theme.variables.gutter}rem

    For screen size (xs) < 576px Container has horizontal padding of 0.5 * {theme.variables.gutter}rem

    You can change the gutter in your theme file just note the same gutter is used Button, Container and Row

    home.js
    import React from 'react'
    import { Container, Heading } from '@therise3107/axis'
    
    const home = ({ children }) => (
        <Container>
            {children}
        </Container>
    )

    Screen-Size

    Width

    xs < 576px

    100%

    sm ≥ 576px

    540px

    md ≥ 768px

    720px

    lg ≥ 992px

    960px

    xl ≥ 1200px

    1140px

    Heading

    Page headings, content headings, this is simply h1, h2...h6

    hashtag
    Usage

    If you are going to use your theme then first you need to define your typography in your theme file like this:

    then, import Heading in your file:

    hashtag
    API Reference

    hashtag
    as? type = String

    defaultProps: 'h1' propTypes: PropTypes.oneOf([ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ])

    hashtag
    align? type = String

    Aligns the text in left, right or center

    defaultProps: undefined propTypes: PropTypes.oneOf([ 'left', 'right', 'center' ])

    hashtag
    density? type = String

    Defines the line-height

    defaultProps: theme.typography.heading.lineHeight propTypes: PropTypes.oneOf(theme.lineHeight)

    circle-info

    this property directly depends on your theme lineHeight

    Example usage:

    hashtag
    size? type = String

    Defines the font size

    defaultProps: theme.typography.heading.fontSize? propTypes: PropTypes.oneOf(theme.typography)

    hashtag
    spacing? type = String

    Defined the letter spacing

    defaultProps: undefined propTypes: PropTypes.oneOf(theme.letterSpacing)

    hashtag
    type? type = String

    Defines the typography, you can use this to provide any css valid css properties

    defaultProps: theme.typography.heading propTypes: PropTypes.oneOf(theme.typography)

    hashtag
    weight? type = String

    Defines the font weight

    defaultProps: theme.typography.heading.fontWeight propTypes: PropTypes.oneOf(theme.fontWeight)

    circle-info

    Please note if you are providing properties via type example <Heading type={typography.primary} />, then using explicit props like spacing, size etc will override the properties provided via typography.primary

    Example usage

    customTheme.js
    ...
    
    const typography = {
        heading: {
            fontFamily: fonts.primaryFont,
        		fontSize: fontSize.lg,
        		fontWeight: fontWeight.normal,
        		lineHeight: 1.2
        },
        headingSecondary: {
            fontFamily: fonts.secondaryFont,
        		fontSize: fontSize.lg,
        		fontWeight: fontWeight.normal,
        		lineHeight: 1.2
        }
    }
    
    home.js
    import React from 'react'
    import { Container, Text } from '@therise3107/axis'
    
    import { fontSize } from 'styles/customTheme' // your theme file
    
    const home = () => (
        <Container>
            <Heading size={fontSize.lg}>Heading h1</Heading>
            <Heading as="h2" size={fontSize.md} type="headingSecondary">
                Heading h2
            </Heading>
        </Container>
    )
    ...
    import { lineHeight } from 'styles/customTheme' // your theme file
    
    const testComponent = () => <Heading density={lineHeight.cozy}>test</Heading> 
    home.js
    import React from 'react'
    import { Container, Heading } from '@therise3107/axis'
    
    import { fontSize } from 'styles/customTheme'
    
    const home = () => (
        <Container>
            <Heading type="headingSecondary">
                This fontSize is coming via typography.headingSecondary.fontSize
            </Heading>
            <Heading type="headingSecondary" size={fontSize.md}>
                This font size is coming via theme.fontSize.md
            </Heading>
        </Container>
    )
    customTheme.js
    ...
    
    const typography = {
        heading: {
            fontFamily: fonts.primaryFont,
        		fontSize: fontSize.lg,
        		fontWeight: fontWeight.normal,
        		lineHeight: 1.2
        },
        headingSecondary: {
            fontFamily: fonts.secondaryFont,
        		fontSize: fontSize.lg,
        		fontWeight: fontWeight.normal,
        		lineHeight: 1.2
        }
    }