Component anatomy.
// Children-driven component<Component prop={value} prop={<ComponentB/>} as='html tag' className={styles.root}><Children/></Component>// Data-driven componentconst children = [<Children/>,<Children/>];<Component items={children} prop={value} className="utility-class"/>
Code snippet hidden
Your screen is too small.
Components should wrap third party code with our own API to make implementation details irrelevant and scope it's domain consistently.
// Component Props might want to extend and/or Pick/Omit.interface DefaultProps {/** subset of HTML tags */as?: 'section' | 'article' | 'nav' | 'aside' | 'header' | 'footer' | 'label' | 'span' | 'p' | 'b' | 'em' | 'strong' | 'time' | 'h1' | 'h2' | 'h3' | 'div';/** Base for composition */children: HTMLElement | ReactElement | ReactNode | Array<ReactNode> | string | null;/** Accepts utility string css class and styles.* from *.module.css */className?: string;/** Available for advanced composition */compose?: unknown;/** Adds to 'root' element */id?: string;/** A11y can be multiple id "myBillingId myNameId" */ariaLabelledby?: string;/** Don't unless you must */discouragedStyle?: CSSProperties;}
Code snippet hidden
Your screen is too small.
Interfaces should adapt to the ratio of the display, there are only two proportions we care about, 'portrait' and 'landscape'. The choice to react current ratio is available to every piece of the interface.
// Access ratio with hookimport {useBreakpoint} from '@/hooks';const Component = (props:Props) => {const { isPortrait } = useBreakpoint();return isPortrait ? <ChildrenPortrait/> : <ChildrenLandscape/>}
Code snippet hidden
Your screen is too small.
Styling flexibility.
// Component stylesimport {clxs} from '@/utils/classname';import styles from 'Component.module.css';const Component = (props:Props) => {const [isActive, setActiveStatus] = useState(false);const rootStyles = clxs('utility-wrapper',props.disabled && styles.disabled,isActive ? styles.active : styles.inactive)return <Children className={rootStyles}/>}
Code snippet hidden
Your screen is too small.