UNPKG

design-react-kit

Version:

Componenti React per Bootstrap 5

1 lines 5.87 kB
{"version":3,"sources":["../../src/Section/Section.tsx","../../src/utils.tsx"],"sourcesContent":["import React, { FC, HTMLAttributes, ReactNode } from 'react';\nimport classNames from 'classnames';\nimport { notifyDeprecation } from '../utils';\n\nexport interface SectionProps extends HTMLAttributes<HTMLElement> {\n /**\n * Classi aggiuntive da usare per il contenitore più esterno\n * Per replicare il comportamento precedente, in cui `className` veniva applicato anche al wrapper,\n * passare `true`.\n * */\n wrapperClassName?: string | true;\n /** Classi aggiuntive da usare per il contenitore più interno */\n className?: string;\n /**\n * Colore utilizzato per lo sfondo del componente Section.\n * In caso di `primary` o `neutral` si consiglia di applicare la classe `.white-color` al contenuto per garantire la leggibilità dei testi.\n * */\n color?: 'primary' | 'neutral' | 'muted' | string;\n /**\n * Indicare l'URL dell'immagine da utilizzare come sfondo della sezione.\n */\n image?: string;\n /** Il contenuto della sezione */\n children?: ReactNode | ReactNode[];\n /** Quando abilitato applica lo sfondo di tipo \"neutral\" al componente.\n * @deprecated. Utilizzare `color=\"neutral\"`\n */\n neutral?: boolean;\n /** Quando abilitato applica lo sfondo di tipo \"muted\" al componente.\n * @deprecated. Utilizzare `color=\"muted\"`\n */\n muted?: boolean;\n testId?: string;\n}\n\nexport const Section: FC<SectionProps> = ({\n color,\n image,\n testId,\n wrapperClassName,\n className,\n children,\n neutral,\n muted,\n ...rest\n}) => {\n const classes = classNames('section', wrapperClassName === true ? className : wrapperClassName, {\n [`section-${color}`]: color,\n 'section-image': image\n });\n\n if (neutral || muted) {\n notifyDeprecation(\n `Please use the prop \"color\" instead of the \"${neutral ? 'neutral' : 'muted'}\" for the Section component.`\n );\n }\n\n // have them separated from the classes above or these will conflict with the color prop\n // concatenate them at the end. Worst case a duplicate class will appear\n const deprecatedClasses = classNames({\n 'section-neutral': neutral,\n 'section-muted': muted\n });\n\n const innerClasses = classNames('section-content', className);\n\n const styleClass = {\n backgroundImageClass: image ? { backgroundImage: `url(${image})` } : {}\n };\n\n const finalWrapperClassName = classNames(classes, deprecatedClasses);\n\n return (\n <div className={finalWrapperClassName} style={styleClass.backgroundImageClass} data-testid={testId} {...rest}>\n <div className={innerClasses}>{children}</div>\n </div>\n );\n};\n","export const noop = () => {};\n\nexport const logError = (message: string) => {\n if (typeof console !== 'undefined') {\n if (console.error) {\n console.error(message);\n } else {\n console.log(message);\n }\n }\n};\n\n// @internal Used for testing purposes only\nexport const flushMessageCache = () => {\n for (const key in messages) {\n delete messages[key];\n }\n};\n\nconst messages: Record<string, 1> = {};\nexport const notifyDeprecation = (message: string, options: { once: boolean } = { once: true }) => {\n if (!options.once) {\n logError(message);\n } else {\n if (!messages[message]) {\n logError(message);\n messages[message] = 1;\n }\n }\n};\n\nexport function mapToCssModules(className: string | null, cssModules?: Record<string, string>) {\n const finalClassNames = className == null ? '' : className;\n if (!cssModules) {\n return finalClassNames;\n }\n return finalClassNames\n .split(' ')\n .map((klass) => cssModules[klass] ?? klass)\n .join(' ');\n}\n\ntype UnknownObject = Record<string, unknown>;\n\nexport function pick<T extends UnknownObject>(obj: T, keys: keyof T | Array<keyof T>): Partial<T> {\n const keysArray = Array.isArray(keys) ? keys : [keys];\n const newObj: Partial<T> = {};\n for (const key of keysArray) {\n if (key in obj) {\n newObj[key] = obj[key];\n }\n }\n return newObj;\n}\n\nexport function omit<T extends UnknownObject>(obj: T, keys: keyof T | Array<keyof T>): Partial<T> {\n const keysLookup = new Set(Array.isArray(keys) ? keys : [keys]);\n\n const newObj: Partial<T> = {};\n for (const key in obj) {\n if (!keysLookup.has(key)) {\n newObj[key] = obj[key];\n }\n }\n return newObj;\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAqD,sBACrDC,EAAuB,2BCChB,IAAMC,EAAYC,GAAoB,CACvC,OAAO,QAAY,MACjB,QAAQ,MACV,QAAQ,MAAMA,CAAO,EAErB,QAAQ,IAAIA,CAAO,EAGzB,EASA,IAAMC,EAA8B,CAAC,EACxBC,EAAoB,CAACC,EAAiBC,EAA6B,CAAE,KAAM,EAAK,IAAM,CAC5FA,EAAQ,KAGNH,EAASE,CAAO,IACnBE,EAASF,CAAO,EAChBF,EAASE,CAAO,EAAI,GAJtBE,EAASF,CAAO,CAOpB,EDMO,IAAMG,EAA4B,CAAC,CACxC,MAAAC,EACA,MAAAC,EACA,OAAAC,EACA,iBAAAC,EACA,UAAAC,EACA,SAAAC,EACA,QAAAC,EACA,MAAAC,EACA,GAAGC,CACL,IAAM,CACJ,IAAMC,KAAU,EAAAC,SAAW,UAAWP,IAAqB,GAAOC,EAAYD,EAAkB,CAC9F,CAAC,WAAWH,CAAK,EAAE,EAAGA,EACtB,gBAAiBC,CACnB,CAAC,GAEGK,GAAWC,IACbI,EACE,+CAA+CL,EAAU,UAAY,OAAO,8BAC9E,EAKF,IAAMM,KAAoB,EAAAF,SAAW,CACnC,kBAAmBJ,EACnB,gBAAiBC,CACnB,CAAC,EAEKM,KAAe,EAAAH,SAAW,kBAAmBN,CAAS,EAEtDU,EAAa,CACjB,qBAAsBb,EAAQ,CAAE,gBAAiB,OAAOA,CAAK,GAAI,EAAI,CAAC,CACxE,EAEMc,KAAwB,EAAAL,SAAWD,EAASG,CAAiB,EAEnE,OACE,EAAAI,QAAA,cAAC,OAAI,UAAWD,EAAuB,MAAOD,EAAW,qBAAsB,cAAaZ,EAAS,GAAGM,GACtG,EAAAQ,QAAA,cAAC,OAAI,UAAWH,GAAeR,CAAS,CAC1C,CAEJ","names":["Section_exports","__export","Section","__toCommonJS","import_react","import_classnames","logError","message","messages","notifyDeprecation","message","options","logError","Section","color","image","testId","wrapperClassName","className","children","neutral","muted","rest","classes","classNames","notifyDeprecation","deprecatedClasses","innerClasses","styleClass","finalWrapperClassName","React"]}