@amaui/ui-react
Version:
UI for React
110 lines • 4.8 kB
JavaScript
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(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import React from 'react';
import { cleanValue, is } from '@amaui/utils';
import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/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: 'amaui-SectionLogos'
});
const Element = /*#__PURE__*/React.forwardRef((props_, ref) => {
const theme = useAmauiTheme();
const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.amauiSectionLogos?.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) && ['amaui-SectionLogos-root', `amaui-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) && ['amaui-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) && ['amaui-SectionLogos-wrapper'], WrapperProps?.className, classes.wrapper, classes[`wrapper_size_${size}`]])
}), /*#__PURE__*/React.createElement(Line, _extends({}, ItemProps, {
fullWidth: true,
className: classNames([staticClassName('SectionLogos', theme) && ['amaui-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) && ['amaui-SectionLogos-name'], classes.name])
}, cleanValue(item?.name || 'No name', {
capitalize: true
}))))));
});
Element.displayName = 'amaui-SectionLogos';
export default Element;