React
Table of contents:
- Render Props
- Replace with Context
Render Props
Use the button's children as label
_11import { forwardRef } from 'react';_11import { Button as KdsButton } from '@kickstartds/base/lib/button';_11_11export const Button = forwardRef(({ children, ...props }, ref) => (_11 <KdsButton {...props} ref={ref} renderLabel={() => children} />_11);_11_11// Usage_11<Button variant="solid" size="medium">_11 Click me_11</Button>;
Allow markdown in label
_14import { forwardRef } from 'react';_14import { Button as KdsButton } from '@kickstartds/base/lib/button';_14import Markdown from 'markdown-to-jsx';_14_14export const Button = forwardRef((props, ref) => (_14 <KdsButton_14 {...props}_14 ref={ref}_14 renderLabel={(label) => <Markdown children={label} />}_14 />_14));_14_14// Usage_14<Button variant="solid" size="medium" label="*Click* me" />;
Replace with Context
_40import { forwardRef } from 'react';_40import {_40 Button as KdsButton,_40 ButtonContext,_40 ButtonContextDefault,_40} from '@kickstartds/base/lib/button';_40import { ContentBox } from "@kickstartds/base/content-box";_40import Markdown from 'markdown-to-jsx';_40_40const Button = forwardRef((props, ref) => (_40 <ButtonContextDefault_40 {...props}_40 ref={ref}_40 renderLabel={(label) => <Markdown children={label} />}_40 />_40));_40_40export const ButtonProvider = (props) => (_40 <ButtonContext.Provider value={Button} {...props} />_40);_40_40// Usage_40<ButtonProvider>_40 <KdsButton variant="solid" size="medium" label="*Click* me" />_40</ButtonProvider>_40_40// Works also with buttons nested in other components_40<ButtonProvider>_40 <ContentBox_40 image="/image.jpg"_40 ratio="16:9"_40 alignement="left"_40 topic="Hey!"_40 link={_40 variant: "solid",_40 size: "medium",_40 label: "*Click* me" // <- !!_40 }_40 />_40</ButtonProvider>