import { getStrWithCapitalized } from "@web3r/flowerkit/str"; import type { ReactElement, ReactNode, FC, CSSProperties, } from "react"; import { Fragment, useMemo } from "react"; import { defaultComponents } from "./config"; import type { IComponentBaseProps } from "../../types/components"; import { useCN } from "../../utils/react/useCN"; import { Btn } from "../btn"; import { Checker } from "../checker"; import { FormatText } from "../formatText"; import { Grid, GridItem } from "../grid"; import { Input } from "../input"; import { Label } from "../label"; import { Palette } from "../palette"; import { Section } from "../section"; import "./style.pcss"; type TComponentsGroups = "text" | "images" | "quotes" | "lists" | "tables" | "headings" | "buttons" | "inputs" | "checkers" | "palette"; type TComponentsProps = Partial<{ getWithDecorator: (content: ReactElement) => ReactElement; children: ReactNode; }> | null; type TComponents = Partial<{ palette: TComponentsProps; text: TComponentsProps; images: TComponentsProps; quotes: TComponentsProps; lists: TComponentsProps; tables: TComponentsProps; headings: TComponentsProps; buttons: TComponentsProps; inputs: TComponentsProps; checkers: TComponentsProps; }>; interface ITypo { /** * выводимые блоки */ components?: TComponents | null; /** * флаг форматирования текста в виде установки неразрывных пробелов и преобразования тире */ isFormatText?: boolean; /** * флаг форматирования текста в виде нормализации стилей сторонних от тегов */ isForceStyles?: boolean; } const PlaceholderImage = ({ width, height, style }: Partial<{ width: number; height: number; style: CSSProperties; }>): ReactElement => { return {""}; }; const PlaceholderTitle = (): ReactNode => { return "Lorem Ipsum is simply dummy text"; }; const PlaceholderText = ({ isShort = false }: { isShort?: boolean; }): ReactNode => { const intro = "There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable."; return isShort ? intro : `${intro} If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.`; }; const TypoContent = ({ group }: { group: TComponentsGroups; }): ReactNode => { switch (group) { case "palette": return ; case "headings": return (

H1: of the printing and typesetting industry.

H2: of the printing and typesetting industry.

H3: of the printing and typesetting industry.

H4: of the printing and typesetting industry.

H5: of the printing and typesetting industry.
H6: of the printing and typesetting industry.
); case "text": return (

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like AldusPageMaker including versions of Lorem Ipsum.

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.


            
          

); case "lists": return (

UL

OL

UL nested

OL nested

); case "quotes": return (

Lorem Ipsum
); case "images": return (

); case "tables": return (
Lorem Ipsum Lorem Ipsum
); case "buttons": { const buttons = [ "default", "light", "outline", ]; const states = [ "default", "hover", "active", "disabled", ]; return ( buttons.map((type, index) => { return ( {states.map((state) => { const id = "btn" + type + getStrWithCapitalized(state); const props = { id, label: `Button`, isOutline: type === "outline", isLight: type === "light", isDisabled: state === "disabled", extraClasses: { isHover: state === "hover", isActive: state === "active", }, }; return ( ); })} {index + 1 !== buttons.length &&
}
); }) ); } case "inputs": { const inputs = [ "text", "textarea", ] as const; const states = [ "default", "hover", "focus", "disabled", "readonly", "invalid", "valid", ]; return inputs.map((type, index) => { return ( {states.map((state) => { const id = "input" + getStrWithCapitalized(type) + getStrWithCapitalized(state); const props = { id, type, isRequired: state === "valid" || state === "invalid", isReadOnly: state === "readonly", isDisabled: state === "disabled", extraClasses: { isInvalid: state === "invalid", isValid: state === "valid", isHover: state === "hover", isFocus: state === "focus", }, }; return ( ); })} {index + 1 !== inputs.length &&
}
); }); } case "checkers": { const checkers = [ "checkbox", "radio", ] as const; const states = [ "default", "checked", "hover", "focus", "disabled", "invalid", "valid", ]; return checkers.map((type, index) => { return ( {states.map((state) => { const id = "input" + getStrWithCapitalized(type) + getStrWithCapitalized(state); const props = { id, type, isRequired: state === "valid" || state === "invalid", isChecked: state === "checked", isDisabled: state === "disabled", extraClasses: { isInvalid: state === "invalid", isValid: state === "valid", isHover: state === "hover", isFocus: state === "focus", }, }; return ( ); })} {index + 1 !== checkers.length &&
}
); }); } default: return null; } }; const TypoBlock = ({ group, children, getWithDecorator }: { group: TComponentsGroups; } & TComponentsProps): ReactNode => { if (children) { return {children}; } else { const component = ; return typeof getWithDecorator === "function" ? getWithDecorator(component) : component; } }; const TypoDefaults = ({ components = {} }: { components: TComponents; }) => { return Object.entries(components) .filter(([ group, options ]) => !!options) .map(([ group, options ]) => { const title = getStrWithCapitalized(group); const { children, getWithDecorator } = options || {}; return (
{title}}> {children}
); }); }; /** * Компонент типографики. Используется для вывода всех возможных элементов визуального редактора и общих UI * @returns {ReactElement} */ const Typo: FC = ({ baseClass = "typo", extraAttrs = {}, extraClasses = {}, style = {}, components = defaultComponents, isForceStyles = true, isFormatText = true, children, }): ReactElement => { const { getCN } = useCN(baseClass); const computedComponents = useMemo(() => { return { ...defaultComponents, ...components, }; }, [ components ]); return (
{!!components && } {(!!children && isFormatText) ? {children} : children}
); }; export type { ITypo }; export { Typo, };