3

i'm looking for a way to integrate grommet framework to a react app created with the cli. I want to use react grommet components inside my app but there are some problems with the preprocessor SCSS. Today, I tried to integrate them in a lot of ways, I followed a lot of tutorials but It still doesn't working. Do you know or do you have success to use them together ? Thankss

1 Answers1

3

For Grommet 1.x

If you don't want to add scss to your project, grommet-css is a great alternative. You can install it and import the css into your App.js.

Note that to customize the default theme you have to fork the repo, make changes like including a different default grommet style in index.scss or tweaking grommet scss variables. Then you have to update the name in package.json, run npm build, then run npm publish.

Here is an example using grommet and grommet-css

import React, { Component } from 'react'

import '../../node_modules/grommet-css';
import Heading from 'grommet/components/Heading';
import Box from 'grommet/components/Box';

export default class GrommetExample extends Component {
  render() {
    return (
      <Box>
            <Heading>Hello, I'm a Grommet Component styled with <a href='https://www.npmjs.com/package/grommet-css'>grommet-css</a></Heading>
      </Box>
    )
  }
}
Tiago Alves
  • 2,290
  • 13
  • 32
  • Thanks Tiago , but in this way I can't use react components of grommet right? I have to use css to manipulate HTML tag. for example I can't use a grommet tag imported from 'grommet/components/Button' but I can only use the grommet css to a traditional HTML button tag, right? – Luca Valsecchi Nov 09 '17 at 21:16
  • You can use grommet components, just make sure you have grommet installed as well :) This package was created to address this specific problem of people that did want to use grommet but didn't want to `eject` their `create-react-app` app. – Tiago Alves Nov 09 '17 at 21:17
  • I try it but it says me : Module not found: can't resolve ;styled components in styledGrimmet.js , vanilla.js and mixins.js – Luca Valsecchi Nov 09 '17 at 21:26
  • If you are using grommet 2.0 you don't need scss (see [changelog](https://github.com/grommet/grommet/wiki/Why-Grommet-2.0%3F#what-is-coming-next)) because they replaced sass with styled-components. When I saw your question I thought you were trying to integrate with grommet 1.x (that uses scss). That is where grommet-css is useful. – Tiago Alves Nov 09 '17 at 21:36
  • yep I have to use it with 1.x version – Luca Valsecchi Nov 09 '17 at 21:39
  • So, the example I just included in my answer should work for you. Just make sure you are using 1.x and have `grommet-css` installed. – Tiago Alves Nov 09 '17 at 21:43
  • I have the error with grommet 1.8.3 and grommet-css (importing grommet-css in app.js ) – Luca Valsecchi Nov 09 '17 at 21:54
  • Tested with v1.8.3 and works just fine here, can you please edit your question with your code? The error you mentioned just happen if you have 2.0 beacuse there was no `styled-components` before that. – Tiago Alves Nov 09 '17 at 21:57