|
| 1 | +// @flow |
| 2 | + |
| 3 | +import * as React from 'react'; |
| 4 | +import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; |
| 5 | +import { darcula } from 'react-syntax-highlighter/dist/styles/prism'; |
| 6 | + |
| 7 | +// import { Checkbox } from 'pretty-checkbox-react'; |
| 8 | + |
| 9 | +import { Title } from '../components/Title'; |
| 10 | +// import { CollapseContainer } from '../components/CollapseContainer'; |
| 11 | + |
| 12 | +const scss = `// @import ... |
| 13 | +
|
| 14 | +.#{$pretty--class-name}.my-icon { |
| 15 | + @extend .#{$pretty--class-name}.p-icon; |
| 16 | +}`; |
| 17 | + |
| 18 | +const jsx = `import { Checkbox } from 'pretty-checkbox-react'; |
| 19 | +
|
| 20 | +<Checkbox className="my-icon" |
| 21 | + icon={<i className="fas fas-question-circle" />}> |
| 22 | + Label |
| 23 | +</Checkbox>`; |
| 24 | + |
| 25 | +const customRender = `<Checkbox>{({ className, node }) => ( |
| 26 | + <div className={classNames("state", className, "custom-handle")}> |
| 27 | + <label>My custom label</label> |
| 28 | + </div> |
| 29 | +)}</Checkbox>`; |
| 30 | + |
| 31 | +const QA = ({ title, children }: { title: React.Node, children: React.Node }) => ( |
| 32 | + <li> |
| 33 | + <p className="q-title">{title}</p> |
| 34 | + <p className="q-resp">{children}</p> |
| 35 | + </li> |
| 36 | +); |
| 37 | + |
| 38 | +function FAQ() { |
| 39 | + return ( |
| 40 | + <> |
| 41 | + <Title>FAQ</Title> |
| 42 | + <div className="content"> |
| 43 | + <ol> |
| 44 | + <QA title={<>Formik overrides <code>p-icon</code> styles</>}> |
| 45 | + If you are using Formik and adding a pretty-checkbox or pretty-checkbox-react component, then you might be seeing visual discrepancies. |
| 46 | + We can get around this by using the render prop or child render function exposed by <strong>pretty-react-checkbox</strong>. |
| 47 | + The easiest way to get around this is to custom build pretty-checkbox <code>.scss</code> source files. |
| 48 | + Once you have that in place we need to make a few tweaks. |
| 49 | + <SyntaxHighlighter language="scss" style={darcula}>{scss}</SyntaxHighlighter> |
| 50 | + With the magic of using Sass <code>@extends</code> we can essentially "copy" the pretty-checkbox base styles to our own selector. |
| 51 | + After this, our usage becomes a bit different as well. |
| 52 | + <SyntaxHighlighter language="jsx" style={darcula}>{jsx}</SyntaxHighlighter> |
| 53 | + Formik will still apply styles to <code>p-icon</code>, but the styles shouldn't clash anymore. |
| 54 | + </QA> |
| 55 | + <QA title="How can I customize pretty-checkbox state div?"> |
| 56 | + Good question! All components offer <code>render</code> prop and <code>children</code> render function support. It's as easy as this: |
| 57 | + <SyntaxHighlighter language="jsx" style={darcula}>{customRender}</SyntaxHighlighter> |
| 58 | + By default the function will return an object containing a <code>className</code> that can be applied -- this is inferred based on the props you pass your base component. |
| 59 | + You can ignore these outright if you wish. Using this approach you can also harness the states exposed by pretty-checkbox. |
| 60 | + </QA> |
| 61 | + </ol> |
| 62 | + </div> |
| 63 | + </> |
| 64 | + ); |
| 65 | +} |
| 66 | + |
| 67 | +export default FAQ; |
0 commit comments