Giter Club home page Giter Club logo

styled-css-grid's Introduction

styled-css-grid ๐Ÿฑ

Travis Prettier npm semantic-release License JS.ORG

A tiny (~2kb) CSS grid layout for React, built with styled-components ๐Ÿ’….

examples

See the website.

installation

Install React and styled-components, then:

$ yarn add styled-css-grid

usage

import React from "react";
import { Grid, Cell } from "styled-css-grid";

const MyGrid = () => (
  <Grid columns={2} gap="2px">
    <Cell>foo</Cell>
    <Cell height={2}>bar</Cell>
    <Cell width={2}>baz</Cell>
  </Grid>
);

api

Grid

Wrap your cells in Grid. Pretty simple.

Props:

  • columns: The grid-template-columns CSS property. When a number is passed it is a shorthand to specify the number of columns. Default is 12.
  • gap: The grid-gap CSS property. Default is "8px".
  • columnGap: The column-gap CSS property. Not provided by default.
  • rowGap: The row-gap CSS property. Not provided by default.
  • minRowHeight: Minimum height of each row. Default is "20px".
  • height: The height CSS property. Default is "auto".
  • flow: The grid-auto-flow CSS property. Default is "row".
  • rows: The grid-template-rows CSS property. When a number is passed it is a shorthand to specify the number of rows. Not provided by default.
  • areas: The grid-template-areas CSS property. Pass an array of strings, e.g. ["a a", "b c"]. Not provided by default.
  • justifyContent: The justify-content CSS property. Not provided by default.
  • alignContent: The align-content CSS property. Not provided by default.

Cell

A cell. Not too much to say...

Props:

  • width: Cell width in units, default is 1.
  • height: Cell height in units, default is 1.
  • left: The grid-column-start CSS property. Not provided by default.
  • top: The grid-row-start CSS property. Not provided by default.
  • middle: Vertically align the contents of the cell. Default is false.
  • center: Horizontally align the text contents of the cell. Default is false.
  • area: The grid-area CSS property. Not provided by default.

browser support

caniuse

You can use CSS grid in production today if you don't need to support IE and Edge, or you're building tooling or internal sites where you only need to support one browser.

You can use CSS grid soon if you have to support the latest version of modern browsers. Edge 16 will implement the latest CSS grid spec.

Can I use?

styled-css-grid's People

Contributors

azz avatar damassi avatar doemski avatar drshpongle avatar fnky avatar james-e-adams avatar jmlweb avatar jordanjustice avatar jvgreenaway avatar kilya11 avatar ladi-j avatar nickduncan7 avatar sugarshin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

styled-css-grid's Issues

Does NOT centering

<Cell middle center>
   <div>Text</div>
</Cell>

Doesn't center if inside it anything else than text.

Add utilities like flexboxgrid

Many of the the utilities implemented in flexboxgrid can be implemented in display: grid, this library should offer shorthands for them too:

  • Offsets (done in #10 via left and top)
  • Alignment (done in #10 via center and middle)
  • Distribution (done in #22 via justifyContent and alignContent)
  • Reordering (done in #10 via flow, left and top)
  • Reversing Not really applicable

styled-components version upgrade

Currently styled-css-grid uses styled-components v2.1.1 and

[email protected]" has incorrect peer dependency "styled-components@^2"

Meanwhile styled-components' current version is v3.4.2.

Basically if the comparability is not terribly broken maybe styled-css-grid should be updated to use a newer version of its main dependency?

Thanks! ๐Ÿ‘Œ

Module not found: Can't resolve 'styled-components'

Does not work from NPM:

Failed to compile.

./node_modules/styled-css-grid/dist/styled-css-grid.esm.js
Module not found: Can't resolve 'styled-components' in 'C:\GitRepos\Beaconsoft\Admin\overload-2\node_modules\styled-css-grid\dist'

Had to manually install styled-components from npm for it to work

Grid gap

Please add support of different gap between rows and columns.

Right now you have:

const gap = ({ gap = "8px" }) => `${gap} ${gap}`;

So if I pass <Grid gap="16px 64px" /> it will result into:

grid-gap: 16px 64px 16px 64px;

which is invalid css value

Pre-render examples

The docs site is currently rendered on the client with ReactDOM.render, but we should be able to pre-render as part of the build step since the content is static.

How do you do a nested grid

  <Grid columns={"1"} justifyContent="center" rowGap="40px">
        <Cell>
            <Grid columns="5">
<Cell></Cell>
<Cell></Cell>
<Cell></Cell>
<Cell></Cell>
<Cell></Cell>
           </Grid>
</Cell>
<Cell></Cell>
.....
</Grid>

The 5 columsn nested doesn't work

Change default number of columns

A 3 column default is nice for demos but in practice a larger number is required. 12 seems to be commonplace in responsive design.

Mixed content on website

Currently the images on the website are served from http://lorempixel.com/ which makes the site mixed content.

[BREAKING CHANGE] Support @emotion/styled

Hello!

I love your little library, and I'd love to be able to leverage it in my ecosystem with @emotion.
My suggestion for the implementation would be to extract the styled component dependency from your library and offer an initialization hook of some sort that could take the styled library of choice as a parameter.

Something like this:

import styled from '@emotion/styled';
import { jsx, css } from '@emotion/core';
import { initialize } from 'styled-css-grid';

initialize({
  package: '@emotion/styled@^10',
  exports: {
    styled,
    jsx,
    css,
  }
});

And then in your code depending on the scope from the initialize function you could have a conditional that branches based on the API of the provided package.

How does that sound?

Have a great day!

Cheers,

Philippe

Example for responsive layout ?

Hi,

I'm using a holy grail type layout. How would I go about hiding the left and right columns on on small screen devices ?

Thanks

Scrollable area

How does one create a grid that has cells with min-height and instead of distributing the size between them - creates a scroll-able area when min-height is reached

dimension

Hi I came across this package and found it really cool. Though I still have few questions about it:

  • Is it possible to add width/height at the grid or grid-item level ?
  • On the Cell the dimensions are in unit so it is not possible to pass in actual dimensions such as 40px ?

Build in responsive breakpoints

Currently in order to be responsive to device width, you must change the columns prop of the <Grid /> component based on the width yourself.

We could add an API to specify breakpoints, that might look something like:

<Grid columns={[
  2,
  ["(min-width: 400px)", 3],
  ["(min-width: 800px)", 4]
]}>
  <Cell>A</Cell><Cell>B</Cell>
  <Cell>C</Cell><Cell>D</Cell>
</Grid>

This way we could use efficient @media rules rather than observing onresize events.

Add theming support

As a styled-css-grid user I would like to change the default value for props like gap without relying on HoCs. Since styled-css-grid uses styled-components maybe leveraging it's theming solution would be a good idea.

Support for theming would be really awesome, is it aligned to styled-css-grid path forward?

Cell middle prop does not work correctly in Firefox

Here you can see <Cell middle> in Chome and Firefox. The layout is incorrect in Firefox.

chrome
firefox

This can be fixed by removing the align-content: space-around style when we apply the middle prop style.

Happy to create a PR if this solution is acceptable.

[suggestion] Grommet grid areas syntax

This is just a suggestion, so feel free to close this if you consider it spam, but i think grommet's "areas" prop for the grid component is very intuitive and gives you a sense of how the whole grid is structured in one place

<Grid
  rows={['xxsmall', 'xsmall']}
  columns={['xsmall', 'small']}
  gap="small"
  areas={[
    { name: 'header', start: [0, 0], end: [1, 0] },
    { name: 'nav', start: [0, 1], end: [0, 1] },
    { name: 'main', start: [1, 1], end: [1, 1] },
  ]}
>
  <Box gridArea="header" background="brand" />
  <Box gridArea="nav" background="light-5" />
  <Box gridArea="main" background="light-2" />
</Grid>

And that it would be very nice to have it in this project. Maybe if i had the time i'd implement it myself if it makes sense for this codebase, but unfortunately i don't have it right now, so it's just a suggestion for the time being. Great project by the way.

overflow: hidden

Hi! Thank you for making this package. I have a question about default styles: what is the reason to keep overflow: hidden for the Cell here ? It brakes absolutely positioned elements (i.e. dropdowns) placed inside.

Width 100%

Hello, first awesome library love it. I have a simple question. In my ui look like the grid never take the full space of his parent. I can't add width: 100% . Do you have a solution for this ?

Support styled-components@5 โ€“ unmet peer dependency

When installing a package with styled-css-grid as a dependency:

npm WARN [email protected] requires a peer of styled-components@^2 || ^3 || ^4 but none is installed. You must install peer dependencies yourself.

In output of npm ls styled-components:

npm ERR! peer dep missing: styled-components@^2 || ^3 || ^4, required by [email protected]

styled-css-grid appears to work fine with styled-components@5 but the peer dependency doesn't account for it. I believe we can add this to support newer releases of styled-components without breaking things for current users of styled-css-grid.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.