From 830b4bee9c738576769b75218dadc6b1de1ba3a3 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 14 Oct 2024 04:06:07 -0500 Subject: Add Admonition component (#5680) * Add Admonition component * Tweak mobile padding * Format --- src/components/Admonition.tsx | 118 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/components/Admonition.tsx (limited to 'src/components') diff --git a/src/components/Admonition.tsx b/src/components/Admonition.tsx new file mode 100644 index 000000000..7c8682119 --- /dev/null +++ b/src/components/Admonition.tsx @@ -0,0 +1,118 @@ +import React from 'react' +import {View} from 'react-native' + +import {atoms as a, useBreakpoints, useTheme} from '#/alf' +import {CircleInfo_Stroke2_Corner0_Rounded as ErrorIcon} from '#/components/icons/CircleInfo' +import {Eye_Stroke2_Corner0_Rounded as InfoIcon} from '#/components/icons/Eye' +import {Leaf_Stroke2_Corner0_Rounded as TipIcon} from '#/components/icons/Leaf' +import {Warning_Stroke2_Corner0_Rounded as WarningIcon} from '#/components/icons/Warning' +import {Text as BaseText, TextProps} from '#/components/Typography' + +const colors = { + warning: { + light: '#DFBC00', + dark: '#BFAF1F', + }, +} + +type Context = { + type: 'info' | 'tip' | 'warning' | 'error' +} + +const Context = React.createContext({ + type: 'info', +}) + +export function Icon() { + const t = useTheme() + const {type} = React.useContext(Context) + const Icon = { + info: InfoIcon, + tip: TipIcon, + warning: WarningIcon, + error: ErrorIcon, + }[type] + const fill = { + info: t.atoms.text_contrast_medium.color, + tip: t.palette.primary_500, + warning: colors.warning.light, + error: t.palette.negative_500, + }[type] + return +} + +export function Text({ + children, + style, + ...rest +}: Pick) { + return ( + + {children} + + ) +} + +export function Row({children}: {children: React.ReactNode}) { + return {children} +} + +export function Outer({ + children, + type = 'info', +}: { + children: React.ReactNode + type?: Context['type'] +}) { + const t = useTheme() + const {gtMobile} = useBreakpoints() + const borderColor = { + info: t.atoms.border_contrast_low.borderColor, + tip: t.atoms.border_contrast_low.borderColor, + warning: t.atoms.border_contrast_low.borderColor, + error: t.atoms.border_contrast_low.borderColor, + }[type] + return ( + + + {children} + + + ) +} + +export function Admonition({ + children, + type, +}: { + children: TextProps['children'] + type?: Context['type'] +}) { + return ( + + + + {children} + + + ) +} -- cgit 1.4.1