@rtslabs/react-components
A library of React component primitives for use in company projects and experiments.
Local Development
Link the local repository using your package manager
machine/repos/rts-react-components $ yarn link
machine/repos/new-react-project $ yarn link @rtslabs/react-components
Installation
Add the following to your package.json
"@rtslabs/react-components": "git+ssh://git@github.com/rtslabs/rts-react-components.git#development",
Component Structuring
Components have been organized as individual modules to allow for future initiatives like separate packaing, tests, documentation, and distribution.
Component Structure
- carousel
- src (component modules)
- Carousel.js
- CarouselSlide.js
- CarouselControls.js
- index.js (exports necessary components from ./src)
- stories.js (storybook stories)
- styles.js (component base styles)
Components
Accordion
Breadcrumbs
Button
Card
Chart
Checkbox
DevAlert
Dropdown
Icon
Input
Layout
Link
Navbar
Sidebar
Table
Tabs
Tooltip
Writing Component Stories
Basic Story Example
;; ; // first argument to storiesOf controls the navigation text in Storybook's sidebarconst stories = ; // first argument to add controls the text in the subnavigationstories;
Theme Structuring
@TODO update once project theme is updated to reflect the theme @chrism has been building for Centivo.
API
create(type, styles)
built on top of styled
from react-emotion
—used for building primitives and extending existing components. Styles passed to create
will be merged with the base styles provided by this library.
ThemeProvider(Component)
Directly exported from emotion-theming
for convenience. Passes theme directly to children via context. Can be used as the root component or anywhere within the component tree. Overriding works as
expected—theme properties from parent ThemeProvider will be overriden by properties from nested ThemeProvider
s.
Overriding Styles
theme
prop
Using the ; const Wrapper = <DangerButton theme= backgroundColor: propsactive ? 'green' : 'grey' />; ;
Presentational Components
; ; const styles = backgroundColor: themecolorsrolesbackground padding: themebuttonspadding ':hover': backgroundColor: themecolorsstateshover ; const DangerButton = ; DangerButtonpropTypes = ... ;DangerButtondefaultProps = ... ; ;
Class Components
;; ; const DangerButtonBase = ; state = clicked: false ; this; { return <DangerButtonBase onClick=thisonClick ...thisprops> thispropschildren </DangerButtonBase> ; } ;