webbeetechnologies / bamboo-molecules

5 stars 0 forks source link

Bamboo Molecules

Goals

Core Principles

What is Bamboo Molecules?

A one place library for React Native Material UI and iOS Cupertino components.\ It aims to provide a solid set of components that can used to create complex platform specific layouts like screens, modals, drawers and navigation.

What does it provide?

Molecules is a set of composed components, a level higher than the un-opinionated Atoms. Following the design pattern, Molecules like Bamboo Atoms; the library is a highly performant, and well tested set of components. Components have been specifically designed to meet the design guidelines of each platform iOS or Android. Bamboo Molecules are opinionated for the platform they cater to.

For the web, the user gets the option to toggle between Material UI and iOS Cupertino style. Molecules components are designed and optimized for the best user experience on the web in both the design styles. Of-course, you can overwrite the styles for any of the platforms using the platform specific extensions. :)

Molecules also exposes an assortment of hooks otherwise not available from bamboo-atoms that make the development experience a breeze.

What does it not do?

Bamboo molecules do not provide a for complex screens and layouts; you can create your own UI layouts using the molecules.

Platforms

Themes

Getting Started

Installation

Simply get started by using the Bamboo Molecules starter template. Alternately, add Bamboo Molecules to an existing project by installing.

yarn add @webbeetechnologies/bamboo-molecules

Usage

Basic usage

import { ProvideMolecules, useMolecules } from "@webbeetechnologies/bamboo-molecules";

const DemoComponent = () => {
  const {View, Text} = useMolecules();
  return (
    <View>
      <Text>Hello World!</Text>
    </View>
  )
}

const App = (props) => {
  return (
    <ProvideMolecules>
      <DemoComponent />
    </ProvideMolecules>
  )
}

export default Component;

Providing Custom Components

Want to provide custom components to use within your app? Simply pass them to provider. useMolecules is a generic, and thus, and thus it will accept an interface and for type inference.

import { ProvideMolecules, useMolecules } from "@webbeetechnologies/bamboo-molecules";

const components = {
  AwesomeStringComponent: (props: { value: string, onChange?: (value: string) => {} }) => <>{ value }</>,
  AwesomeNumberComponent: (props: { value: number, onChange?: (value: number) => {} }) => <>{ value }</>,
}

const useAwesomeAppComponents = () => useMolecules<typeof components>();

const DemoComponent = () => {
  const {View, AwesomeStringComponent, AwesomeNumberComponent} = useAwesomeAppComponents();
  return (
    <View>
      <AwesomeStringComponent value="Hello World" />
      <AwesomeNumberComponent value={42} />
    </View>
  )
}

const App = (props) => {
  return (
    <ProvideMolecules components={components}>
      <DemoComponent />
    </ProvideMolecules>
  )
}
export default App;

Theming

Want to provide a custom theme or extend the existing components; easy.\ Make a custom style definition for your components by using the extendTheme function. Bamboo molecules implement platform specific design tokens that can be also be easily.

const theme = extendTheme({ AwesomeStringComponent: { color: "colors.onPrimary", backgroundColor: "colors.primary", }, Button: { backgroundColor: "colors.primary", text: "colors.onPrimary", states: { disabled: { backgroundColor: "red", text: "black", }, hovered: { backgroundColor: "colors.primaryOnHover", } } } });

const DemoComponent = () => { const {Button} = useMolecules(); return (