UNPKG

@onesy/ui-react

Version:
110 lines 4.65 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["values", "size", "name", "gray", "ItemProps", "WrapperProps", "className"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import React from 'react'; import { cleanValue, is } from '@onesy/utils'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import LineElement from '../Line'; import SectionElement from '../Section/Section'; import TypeElement from '../Type'; import { staticClassName } from '../utils'; const useStyle = styleMethod(theme => ({ root: {}, name: { wordBreak: 'break-word' }, items: { overflow: 'auto hidden', padding: `${theme.methods.space.value(2, 'px')} 0`, maxWidth: '100%' }, wrapper: { flex: '0 0 auto' }, wrapper_size_small: { width: '154px' }, wrapper_size_regular: { width: '214px' }, wrapper_size_large: { width: '274px' }, item: { aspectRatio: '16 / 9', backgroundSize: 'contain', backgroundPosition: 'center', backgroundRepeat: 'no-repeat' }, gray: { filter: 'grayscale(1)' } }), { name: 'onesy-SectionLogos' }); const Element = /*#__PURE__*/React.forwardRef((props_, ref) => { const theme = useOnesyTheme(); const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesySectionLogos?.props?.default), props_), [props_]); const Line = React.useMemo(() => theme?.elements?.Line || LineElement, [theme]); const Section = React.useMemo(() => theme?.elements?.Section || SectionElement, [theme]); const Type = React.useMemo(() => theme?.elements?.Type || TypeElement, [theme]); const { values = [], size = 'regular', name, gray, ItemProps, WrapperProps, className } = props, other = _objectWithoutProperties(props, _excluded); const { classes } = useStyle(); const refs = { root: React.useRef(undefined) }; return /*#__PURE__*/React.createElement(Section, _extends({ ref: item => { if (ref) { if (is('function', ref)) ref(item);else ref.current = item; } refs.root.current = item; }, align: "center", MainProps: { justify: 'center', align: 'center' }, className: classNames([staticClassName('SectionLogos', theme) && ['onesy-SectionLogos-root', `onesy-SectionLogos-size-${size}`], className, classes.root]) }, other), /*#__PURE__*/React.createElement(Line, { gap: size === 'large' ? 10 : size === 'regular' ? 8 : 6, direction: "row", justify: "flex-start", align: "center", className: classNames([staticClassName('SectionLogos', theme) && ['onesy-SectionLogos-items'], classes.items, gray && classes.gray]) }, values?.map((item, index) => /*#__PURE__*/React.createElement(Line, _extends({ key: index }, WrapperProps, { fullWidth: true, className: classNames([staticClassName('SectionLogos', theme) && ['onesy-SectionLogos-wrapper'], WrapperProps?.className, classes.wrapper, classes[`wrapper_size_${size}`]]) }), /*#__PURE__*/React.createElement(Line, _extends({}, ItemProps, { fullWidth: true, className: classNames([staticClassName('SectionLogos', theme) && ['onesy-SectionLogos-item'], ItemProps?.className, classes.item]), style: { backgroundImage: `url(${item?.url || item?.urlSmall})` } })), name && /*#__PURE__*/React.createElement(Type, { version: size === 'large' ? 't1' : size === 'regular' ? 't2' : 't3', align: "center", fullWidth: true, className: classNames([staticClassName('SectionLogos', theme) && ['onesy-SectionLogos-name'], classes.name]) }, cleanValue(item?.name || 'No name', { capitalize: true })))))); }); Element.displayName = 'onesy-SectionLogos'; export default Element;