diff --git a/packages/react/components/Popout/index.mjs b/packages/react/components/Popout/index.mjs index 42bf67bf1ba..bb8583503a7 100644 --- a/packages/react/components/Popout/index.mjs +++ b/packages/react/components/Popout/index.mjs @@ -1,108 +1,141 @@ import React, { useState } from 'react' import { CloseIcon } from '@freesewing/react/components/Icon' -const colors = { - comment: 'secondary', - error: 'error', - fixme: 'warning', - link: 'secondary', - none: '', - note: 'primary', - related: 'info', - tip: 'accent', - tldr: 'info', - warning: 'error', +/* + * Resist the urge to DRY this up by contructing classNames dynamically + * as doing so will cause them to be dropped from the production bundle + */ +const types = { + comment: { + bg: 'tw:bg-success/5', + border: 'tw:border-success', + text: 'tw:text-success', + }, + error: { + bg: 'tw:bg-error/5', + border: 'tw:border-error', + text: 'tw:text-error', + }, + fixme: { + bg: 'tw:bg-neutral/5', + border: 'tw:border-neutral', + text: 'tw:text-error', + }, + link: { + bg: 'tw:bg-secondary/5', + border: 'tw:border-secondary', + text: 'tw:text-secondary', + }, + note: { + bg: 'tw:bg-primary/5', + border: 'tw:border-primary', + text: 'tw:text-primary', + }, + related: { + bg: 'tw:bg-info/5', + border: 'tw:border-info', + text: 'tw:text-info', + }, + tip: { + bg: 'tw:bg-accent/5', + border: 'tw:border-accent', + text: 'tw:text-accent', + }, + warning: { + bg: 'tw:bg-warning/5', + border: 'tw:border-warning', + text: 'tw:text-warning', + }, } /** * This popout component is a way to make some content stand out * + * @component * @param {object} props - All React props - * @param {object} props.comment - Set this to make it a comment popout - * @param {object} props.error - Set this to make it a error popout - * @param {object} props.fixme - Set this to make it a fixme popout - * @param {object} props.link - Set this to make it a link popout - * @param {object} props.note - Set this to make it a note popout - * @param {object} props.related - Set this to make it a related popout - * @param {object} props.tip - Set this to make it a tip popout - * @param {object} props.tldr - Set this to make it a tldr popout - * @param {object} props.warning - Set this to make it a warning popout - * @param {string} props.title - The popout title - * @param {string} noP - Do not wrap the content in a p tag + * @param {string} [props.by = false] - When type is comment, this will be used to show who made the comment + * @param {JSX.Element} props.children - The component children, will be rendered if props.js is not set + * @param {boolean} [props.compact = false] - Set this to render a compact style + * @param {boolean} [props.dense = false] - Set this to render a dense style (only for compact view) + * @param {boolean} [props.hideable = false] - Set this to make the popout hideable/dismissable + * @param {string} [props.type = note] - One of the available types: comment, error, fixme, link, note, related, tip, warning + * @param {string} [props.title = false] - Set this to use a custom title + * @returns {JSX.Element} */ -export const Popout = (props) => { +export const Popout = ({ + by = false, + children = null, + compact = false, + dense = false, + hideable = false, + type = "note", + title = false, +}) => { // Make this hideable/dismissable const [hide, setHide] = useState(false) + if (hide) return null - let type = 'none' - for (const c in colors) { - if (props[c]) type = c - } - const color = colors[type] - const { className = '' } = props - - return props.compact ? ( -
{props.children}
}by
prop to indicate the authorby
prop to indicate the authorby
prop to indicate the authorhideable
tip