-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please document how to import js into a 'create-react-app' project #1330
Comments
I'm using this in CRA, and it's quite simple. You're almost there. You just need to import the components you want to use from the semantic-ui-react module, using the ES6 import syntax. import React, { Component } from 'react';
import { Button, Icon, Grid } from 'semantic-ui-react';
class ExampleComponent extends Component {
render() {
return (
<Grid>
<Grid.Column width={15}>
<p>
Lorem ipsum...
</p>
</Grid.Column>
<Grid.Column width={1}>
<Button basic circular icon="photo" floated="right" />
<Button basic circular icon="video" floated="right" style={{marginTop: 5}}/>
</Grid.Column>
</Grid>
)
}
}
export default ExampleComponent; Optionally you can use the CommonJS require syntax if you're not using ES6: var Button = require('semantic-ui-react').Button; You'll want these to be saved as dependencies, not dev-dependencies. From the npm documentation:
|
@andrewhl Just realized the Usage page may not be obvious to newcomers. Your comment should be included in the docs under the JavaScript section. |
@AaronHarris @realtebo I will submit a PR. |
Every example for every component includes fully functional import statements. I chose to include import statements in the browser hoping to clarify exactly this issue. I wanted the examples to be fully functional so that newcomers could copy the full example to their project and it would work exactly as is. I can see how these could be missed during first time setup as you'd have to click the code icon on one of the examples to see them. Can anyone comment on whether or not they saw these code examples and how they might be more helpful? http://react.semantic-ui.com/elements/button |
@levithomason I think the pattern for code examples being completely literal is great. The UI pattern to see a code example upon clicking the icon to see it expanded is also something people should be familiar with from other UI kit docs. Basically I think the current examples are great, especially for those very new to React. I don't think there's a way to make it simpler for those new to React or ES6 syntax for using imports other than maybe a paragraph and a screenshot in the setup docs that points out the two buttons showing the React component usage and the rendered HTML. |
Yes, I agree. As newbie, I thinked, seeing a row for importing css, that there will be a row about import a module. The compromise could be to simply add a row explaining that "we will not import a module, but single pieces when needed (see the docs, for example [then add a link to Button] )." |
IS is possible to import individual components from this lib using create react app without ejecting? |
@jasan-s yes, see #1522 (comment). We support using any bundler or no bundler. tl;dr import Button from 'semantic-ui-react/dist/commonjs/elements/Button' |
Your import isn't correct, there is missing |
I can't get the css import to work in a new create-react-app project. Has something changed?
edit: Something has changed! The import path for the css file is now:
Found it by RTFM here: https://react.semantic-ui.com/usage#semantic-ui-css-package Sorry for the noise. |
I ran into this issue today. It looks like everyone resolved this issue by just using the What about for people who want to use the whole package? I installed the full package because I want the theming capabilities:
Using this generates a lot of files and directories which happens after resolving a bug regarding Semantic UI's install script and yarn. Among these generated stuff is a configuration that tells gulp to compile SUI into the The
This won't work because the compiled file is outside |
@terenceponce I run my current project with a full install of SUI core because I also use the theming capabilities. When you install the core SUI project, you can pick where the output files go. Don't run the default install. Instead go through the custom install. You can also select the components you need too and get a smaller CSS package if you are not using everything. Just change the |
@brianespinosa How do you run the custom installation through Yarn? As for the location, it looks like there really is no way around putting the |
@terenceponce when you FIRST install These attributes control where your build files go: Setting There's also a root attribute called None of the above has anything to do with how SUIR works by the way. If you require additional help with customizing the build location of your SUI core package, you'll receive better help in the core repository... but hopefully this gets you what you need. |
I'm starting usign create-react-app to create a new project.
I understand I need both
and
For the csss I can
But how to import the javascript?
Also: are them dependecies or dev-dependencies ?
The text was updated successfully, but these errors were encountered: