airbnb.io - react-with-styles Use CSS-in-JavaScript with themes for React without being tightly coupled to one implementation1,242









Search Preview

Airbnb Engineering & Data Science

airbnb.io
Airbnb.io Open SourceEventsBlogGithubCareersAirbnb.io react-with-stylesUse CSS-in-JavaScript with themes for React without being tightly coupled to one im
.io > airbnb.io

SEO audit: Content analysis

Language Error! No language localisation is found.
Title Airbnb Engineering & Data Science
Text / HTML ratio 48 %
Frame Excellent! The website does not use iFrame solutions.
Flash Excellent! The website does not have any flash contents.
Keywords cloud import styles withStyles default color theme React css unit MyComponent
export prop function return colorprimary component > 'withStyles' 'react'
Keywords consistency
Keyword Content Title Description Headings
import 25
styles 24
withStyles 20
default 20
color 20
theme 18
Headings
H1 H2 H3 H4 H5 H6
1 9 6 3 0 0
Images We found 1 images on this web page.

SEO Keywords (Single)

Keyword Occurrence Density
import 25 1.25 %
styles 24 1.20 %
withStyles 20 1.00 %
default 20 1.00 %
color 20 1.00 %
theme 18 0.90 %
React 16 0.80 %
css 12 0.60 %
unit 12 0.60 %
MyComponent 11 0.55 %
10 0.50 %
export 10 0.50 %
prop 10 0.50 %
function 10 0.50 %
return 9 0.45 %
colorprimary 9 0.45 %
component 9 0.45 %
> 9 0.45 %
'withStyles' 8 0.40 %
'react' 8 0.40 %

SEO Keywords (Two Word)

Keyword Occurrence Density
css withStyles 10 0.50 %
export default 9 0.45 %
import css 8 0.40 %
color colorprimary 8 0.40 %
from 'react' 8 0.40 %
'react' import 8 0.40 %
import React 8 0.40 %
from 'withStyles' 8 0.40 %
default theme 7 0.35 %
to be 7 0.35 %
React from 7 0.35 %
withStyles from 7 0.35 %
function MyComponent 6 0.30 %
return 6 0.30 %
unit => 6 0.30 %
'withStyles' function 6 0.30 %
marginBottom 2 6 0.30 %
=> container 6 0.30 %
container color 6 0.30 %
colorprimary marginBottom 6 0.30 %

SEO Keywords (Three Word)

Keyword Occurrence Density Possible Spam
import css withStyles 8 0.40 % No
from 'react' import 8 0.40 % No
import React from 7 0.35 % No
React from 'react' 7 0.35 % No
withStyles from 'withStyles' 7 0.35 % No
css withStyles from 7 0.35 % No
unit => container 6 0.30 % No
'react' import css 6 0.30 % No
color unit => 6 0.30 % No
container color colorprimary 6 0.30 % No
=> container color 6 0.30 % No
color colorprimary marginBottom 6 0.30 % No
colorprimary marginBottom 2 6 0.30 % No
marginBottom 2 unit 6 0.30 % No
from 'withStyles' function 6 0.30 % No
'withStyles' function MyComponent 5 0.25 % No
withStyles color unit 5 0.25 % No
export default
5 0.25 % No
be a rainbow 5 0.25 % No
to be a 5 0.25 % No

SEO Keywords (Four Word)

Keyword Occurrence Density Possible Spam
React from 'react' import 7 0.35 % No
css withStyles from 'withStyles' 7 0.35 % No
import css withStyles from 7 0.35 % No
import React from 'react' 7 0.35 % No
withStyles from 'withStyles' function 6 0.30 % No
colorprimary marginBottom 2 unit 6 0.30 % No
color colorprimary marginBottom 2 6 0.30 % No
container color colorprimary marginBottom 6 0.30 % No
=> container color colorprimary 6 0.30 % No
unit => container color 6 0.30 % No
color unit => container 6 0.30 % No
from 'react' import css 6 0.30 % No
'react' import css withStyles 6 0.30 % No
from 'withStyles' function MyComponent 5 0.25 % No
Try to be a 5 0.25 % No
export default withStyles color 5 0.25 % No
withStyles color unit => 5 0.25 % No
to be a rainbow 5 0.25 % No
be a rainbow in 4 0.20 % No
a rainbow in someone's 4 0.20 % No

Internal links in - airbnb.io

Open Source
Airbnb Engineering & Data Science
Events
Airbnb Engineering & Data Science
Airflow Use Apache Airflow (incubating) to author workflows as directed acyclic graphs (DAGs) of tasks8,613
Airbnb Engineering & Data Science
Aerosolve A machine learning package built for humans4,385
Airbnb Engineering & Data Science
BinaryAlert Serverless real-time and retroactive malware detection705
Airbnb Engineering & Data Science
AirMapView A view abstraction to provide a map user interface with various underlying map providers1,583
Airbnb Engineering & Data Science
Airpal Web UI for PrestoDB2,345
Airbnb Engineering & Data Science
DeepLinkDispatch Easy declaration and routing of your deep links2,990
Airbnb Engineering & Data Science
Enzyme JavaScript Testing utilities for React14,372
Airbnb Engineering & Data Science
Hammerspace Hash-like interface to persistent, concurrent, off-heap storage302
Airbnb Engineering & Data Science
Hypernova A service for server-side rendering your JavaScript views4,266
Airbnb Engineering & Data Science
Epoxy An Android library for building complex screens in a RecyclerView4,301
Airbnb Engineering & Data Science
Interferon Signaling you about infrastructure or application issues178
Airbnb Engineering & Data Science
JavaScript Style Guide A mostly reasonable approach to JavaScript73,101
Airbnb Engineering & Data Science
The Knowledge Repo A next-generation curated knowledge sharing platform for data scientists and other technical professions2,992
Airbnb Engineering & Data Science
Polyglot Give your JavaScript the ability to speak many languages2,734
Airbnb Engineering & Data Science
Nerve A service registration daemon that performs health checks; companion to airbnb/synapse837
Airbnb Engineering & Data Science
mocha-wrap Fluent pluggable interface for easily wrapping `describe` and `it` blocks in Mocha tests39
Airbnb Engineering & Data Science
Rheostat Rheostat is a www, mobile, and accessible slider component built with React1,248
Airbnb Engineering & Data Science
ReAir A collection of easy-to-use tools for replicating tables and partitions between Hive data warehouses206
Airbnb Engineering & Data Science
react-dates An accessible, easily internationalizable, mobile-friendly datepicker library for the web7,757
Airbnb Engineering & Data Science
Ruby Style Guide Airbnb's Ruby Style Guide2,366
Airbnb Engineering & Data Science
react-with-styles Use CSS-in-JavaScript with themes for React without being tightly coupled to one implementation1,242
Airbnb Engineering & Data Science
Superset Apache Superset (incubating) is a modern, enterprise-ready business intelligence web application19,842
Airbnb Engineering & Data Science
RxGroups Easily group RxJava Observables together and tie them to your Android Activity lifecycle668
Airbnb Engineering & Data Science
StreamAlert A serverless framework for real-time data analysis and alerting1,406
Airbnb Engineering & Data Science
Stemcell Airbnb's EC2 instance creation and bootstrapping tool157
Airbnb Engineering & Data Science
Synapse A transparent service discovery framework for connecting an SOA1,830
Airbnb Engineering & Data Science

Airbnb.io Spined HTML


Airbnb Engineering & Data Science Airbnb.io Open SourceEventsBlogGithubCareersAirbnb.io react-with-stylesUse CSS-in-JavaScript with themes for React without stuff tightly coupled to one implementation1,242By Joe LencioniUse CSS-in-JavaScript for your React components without stuff tightly coupled to one implementation (e.g. Aphrodite, Radium, or React Native). Easily wangle shared theme information (e.g. colors, fonts) when defining your styles. Interfaces Aphrodite JSS React Native Other resources eslint-plugin-react-with-styles: ESLint plugin for react-with-styles. How to use Create a module that exports an object with shared theme information like colors. export default { color: { primary: '#FF5A5F', secondary: '#00A699', }, }; Register your default theme and interface. For example, if your default theme is exported by MyDefaultTheme.js, and you want to use Aphrodite, you can set this up in your own withStyles.js file. import ThemedStyleSheet from 'react-with-styles/lib/ThemedStyleSheet'; import aphroditeInterface from 'react-with-styles-interface-aphrodite'; import { css, withStyles, ThemeProvider } from 'react-with-styles'; import MyDefaultTheme from './MyDefaultTheme'; ThemedStyleSheet.registerDefaultTheme(MyDefaultTheme); ThemedStyleSheet.registerInterface(aphroditeInterface); export { css, withStyles, ThemeProvider, ThemedStyleSheet }; It is user-friendly to pass through css, withStyles, and ThemeProvider from react-with-styles here so that everywhere you use them you can be unpreventable that the default theme and interface have been registered. You could likely moreover set this up as an initializer that is widow to the top of your bundles and then use react-with-styles directly in your components. In your component, from our withStyles.js file above, use withStyles() to pinpoint styles and css() to slosh them. import React, { PropTypes } from 'react'; import { css, withStyles } from './withStyles'; function MyComponent({ styles }) { return ( <div> <a href="/somewhere" {...css(styles.firstLink)} > A link to somewhere </a> {' '} and {' '} <a href="/somewhere-else" {...css(styles.secondLink)} > a link to somewhere else </a> </div> ); } MyComponent.propTypes = { styles: PropTypes.object.isRequired, }; export default withStyles(({ verisimilitude }) => ({ firstLink: { color: color.primary, }, secondLink: { color: color.secondary, }, }))(MyComponent); ThemedStyleSheet Registers themes and interfaces. ThemedStyleSheet.registerDefaultTheme(theme) Registers the default theme. theme is an object with properties that you want to be made misogynist when styling your components. import ThemedStyleSheet from 'react-with-styles/lib/ThemedStyleSheet'; ThemedStyleSheet.registerDefaultTheme({ color: { primary: '#FF5A5F', secondary: '#00A699', }, }); ThemedStyleSheet.registerTheme(name, overrides) Registers a named theme that defines overrides for the default theme. This object is merged with the default theme. import ThemedStyleSheet from 'react-with-styles/lib/ThemedStyleSheet'; ThemedStyleSheet.registerTheme('tropical', { color: { primary: 'yellow', }, }); Combined with the whilom example for default theme, color.primary would be 'yellow' and color.secondary would be '#00A699'. ThemedStyleSheet.registerInterface(interface) Instructs react-with-styles how to process your styles. import ThemedStyleSheet from 'react-with-styles/lib/ThemedStyleSheet'; import aphroditeInterface from 'react-with-styles-interface-aphrodite'; ThemedStyleSheet.registerInterface(aphroditeInterface); <ThemeProvider name="theme name"> This component simply takes a name prop that matches a registered theme, and stores that value in context. This allows sub-trees of your using to transpiration to variegated themes as necessary. import React from 'react'; import { ThemeProvider } from './withStyles'; export default function App() { return ( <div> <MyComponent /> <ThemeProvider name="tropical"> <MyComponent /> </ThemeProvider> </div> ); } withStyles([ stylesThunk [, options ] ]) This is a higher-order function that returns a higher-order component used to wrap React components to add styles using the theme provided from context. We use this to utopian yonder the context, to make themed styles easier to work with. stylesThunk will receive the theme as an argument, and it should return an object containing the styles for the component. The wrapped component will receive a styles prop containing the processed styles for this component and a theme prop with the current theme object. Most of the time you will only need the styles prop. Reliance on the theme prop should be minimized. Example usage import React from 'react'; import { css, withStyles } from './withStyles'; function MyComponent({ styles }) { return ( <div {...css(styles.container)}> Try to be a rainbow in someone's cloud. </div> ); } export default withStyles(({ color, unit }) => ({ container: { color: color.primary, marginBottom: 2 * unit, }, }))(MyComponent); Or, as a decorator: import React from 'react'; import { css, withStyles } from './withStyles'; @withStyles(({ color, unit }) => ({ container: { color: color.primary, marginBottom: 2 * unit, }, })) export default function MyComponent({ styles }) { return ( <div {...css(styles.container)}> Try to be a rainbow in someone's cloud. </div> ); } Options stylesPropName (default: 'styles') By default, withStyles() will pass lanugo the styles to the wrapped component in the styles prop, but the name of this prop can be customized by setting the stylesPropName option. This is useful if you once have a prop tabbed styles and aren't worldly-wise to transpiration it. import React from 'react'; import { css, withStyles } from './withStyles'; function MyComponent({ withStylesStyles }) { return ( <div {...css(withStylesStyles.container)}> Try to be a rainbow in someone's cloud. </div> ); } export default withStyles(({ color, unit }) => ({ container: { color: color.primary, marginBottom: 2 * unit, }, }), { stylesPropName: 'withStylesStyles' })(MyComponent); themePropName (default 'theme') Likewise, the theme prop name can moreover be customized by setting the themePropName option. import React from 'react'; import { css, withStyles } from './withStyles'; function MyComponent({ styles, withStylesTheme }) { return ( <div {...css(styles.container)}> <Background color={withStylesTheme.color.primary}> Try to be a rainbow in someone's cloud. </Background> </div> ); } export default withStyles(({ color, unit }) => ({ container: { color: color.primary, marginBottom: 2 * unit, }, }), { themePropName: 'withStylesTheme' })(MyComponent); flushBefore (default: false) Some components depend on previous styles to be ready in the component tree when mounting (e.g. dimension calculations). Some interfaces add styles to the page asynchronously, which is an obstacle for this. So, we provide the option of flushing the buffered styles surpassing the rendering trundling begins. It is up to the interface to pinpoint what this means. css(...styles) This function takes styles that were processed by withStyles(), plain objects, or arrays of these things. It returns an object with an opaque structure that must be spread into a JSX element. import React from 'react'; import { css, withStyles } from './withStyles'; function MyComponent({ bold, padding, styles }) { return ( <div {...css(styles.container, { padding })}> Try to be a rainbow in{' '} <a href="/somewhere" {...css(styles.link, unvigilant && styles.link_bold)} > someone's deject </a> </div> ); } export default withStyles(({ color, unit }) => ({ container: { color: color.primary, marginBottom: 2 * unit, }, link: { color: color.secondary, }, link_bold: { fontWeight: 700, }, }))(MyComponent); className and style props must not be used on the same elements as css(). Examples With React Router's Link React Router's <Link/> and <IndexLink/> components winnow activeClassName='...' and activeStyle={{...}} as props. As previously stated, css(...styles) must spread to JSX, so simply passing styles.thing or plane css(styles.thing) directly will not work. In order to mimic activeClassName/activeStyles you can use React Router's withRouter() Higher Order Component to pass router as prop to your component and toggle styles based on router.isActive(pathOrLoc, indexOnly). This works considering <Link /> passes lanugo the generated className from css(..styles) lanugo through to the final leaf. import React from 'react'; import { withRouter, Link } from 'react-router'; import { css, withStyles } from '../withStyles'; function Nav({ router, styles }) { return ( <div {...css(styles.container)}> <Link to="/" {...css(styles.link, router.isActive('/', true) && styles.link_bold)} > home </Link> <Link to="/somewhere" {...css(styles.link, router.isActive('/somewhere', true) && styles.link_bold)} > somewhere </Link> </div> ); } export default withRouter(withStyles(({ color, unit }) => ({ container: { color: color.primary, marginBottom: 2 * unit, }, link: { color: color.primary, }, link_bold: { fontWeight: 700, } }))(Nav)); In the wild Organizations and projects using react-with-styles.LinksGithubCSS-in-JavaScript style guideeslint plugin© Airbnb, Inc.© Airbnb, Inc.CareersDesignCareersDesignCareersDesign