@amaui/ui-react
Version:
UI for React
235 lines • 11.4 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 = ["size", "values", "ItemProps", "ItemsProps", "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 { useNavigate } from 'react-router-dom';
import { is, isEnvironment, textToInnerHTML } from '@amaui/utils';
import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/style-react';
import SectionElement from '../Section/Section';
import LineElement from '../Line';
import TypeElement from '../Type';
import ButtonElement from '../Button';
import { staticClassName } from '../utils';
const useStyle = styleMethod(theme => ({
root: {},
main: {
maxWidth: '768px',
zIndex: '14'
},
items: {
padding: `${theme.methods.space.value(2, 'px')} 0`,
overflow: 'auto hidden',
maxWidth: '100%'
},
item: {
position: 'relative',
flex: '0 0 auto',
width: '100%',
background: theme.palette.background.default.primary,
'&:active': {
'& $background': {
borderRadius: theme.methods.shape.radius.value(5)
}
}
},
item_size_small: {
maxWidth: '174px'
},
item_size_regular: {
maxWidth: '254px'
},
item_size_large: {
maxWidth: '314px'
},
actions: {
marginTop: 12
},
background: {
position: 'relative',
aspectRatio: '3 / 4',
borderRadius: theme.methods.shape.radius.value(3),
zIndex: '1',
transition: theme.methods.transitions.make('border-radius')
},
backgroundImage: {
backgroundSize: 'cover',
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat'
},
backgroundVideo: {
position: 'absolute',
inset: '0',
minHeight: '100%',
minWidth: '100%',
top: '50%',
transform: 'translateY(-50%)',
zIndex: '1'
},
backgroundOverlay: {
position: 'absolute',
inset: '0',
zIndex: '4'
},
backgroundOverlayBlur: {
backdropFilter: 'blur(12px)'
}
}), {
name: 'amaui-SectionCards'
});
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?.amauiSectionCards?.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 Button = React.useMemo(() => theme?.elements?.Button || ButtonElement, [theme]);
const {
size = 'regular',
values = [],
ItemProps,
ItemsProps,
className
} = props,
other = _objectWithoutProperties(props, _excluded);
const {
classes
} = useStyle();
const navigate = isEnvironment('browser') && useNavigate();
const refs = {
root: React.useRef(undefined)
};
const getItem = React.useCallback((item, index) => {
let styleBackground = {};
const themed = [undefined, true].includes(item.themed);
if (item.backgroundColor) {
const palette = theme.palette.color[item.backgroundColor] || theme.methods.color(item.backgroundColor);
styleBackground = _objectSpread(_objectSpread({}, styleBackground), {}, {
backgroundColor: themed ? theme.methods.palette.color.value(undefined, 95, true, palette) : palette?.main
});
}
if (is('array', item.backgroundGradient) && item.backgroundGradient.length >= 2) {
const palette1 = theme.palette.color[item.backgroundGradient[0]] || theme.methods.color(item.backgroundGradient[0]);
const palette2 = theme.palette.color[item.backgroundGradient[1]] || theme.methods.color(item.backgroundGradient[1]);
const palette3 = theme.palette.color[item.backgroundGradient[2]] || theme.methods.color(item.backgroundGradient[2]);
let backgroundImageStyle = '';
if (item.backgroundGradient?.length === 2) {
backgroundImageStyle = themed ? `linear-gradient(${theme.palette.light ? '130deg' : '330deg'}, ${theme.methods.palette.color.colorToRgb(palette1.main, 0.14)} 0%, ${theme.methods.palette.color.colorToRgb(palette2.main, 0.14)} 100%)` : `linear-gradient(${theme.palette.light ? '130deg' : '330deg'}, ${palette1.main} 0%, ${palette2.main} 100%)`;
}
if (item.backgroundGradient?.length === 3) {
backgroundImageStyle = themed ? `linear-gradient(${theme.palette.light ? '130deg' : '330deg'}, ${theme.methods.palette.color.colorToRgb(palette1.main, 0.14)} 0%, ${theme.methods.palette.color.colorToRgb(palette2.main, 0.14)} 40%, ${theme.methods.palette.color.colorToRgb(palette3.main, 0.14)} 100%)` : `linear-gradient(${theme.palette.light ? '130deg' : '330deg'}, ${palette1.main} 0%, ${palette2.main} 40%, ${palette3.main} 100%)`;
}
styleBackground = _objectSpread(_objectSpread({}, styleBackground), {}, {
backgroundImage: backgroundImageStyle
});
}
if (item.backgroundImage) {
const url = item.backgroundImage?.url || item.backgroundImage?.urlSmall || (is('string', item.backgroundImage) ? item.backgroundImage : '');
if (url) {
styleBackground = _objectSpread(_objectSpread({}, styleBackground), {}, {
backgroundImage: `url('${url}')`
});
}
}
let styleOverlay = {};
if (item.overlay) {
const palette = theme.palette.color[item.overlay] || theme.methods.color(item.overlay);
styleOverlay = _objectSpread(_objectSpread({}, styleOverlay), {}, {
backgroundColor: themed ? theme.methods.palette.color.alpha(theme.methods.palette.color.value(undefined, 95, true, palette), 0.74) : palette?.main
});
}
const urlVideo = item.backgroundVideo?.url || item.backgroundVideo?.urlSmall || (is('string', item.backgroundVideo) ? item.backgroundVideo : '');
return /*#__PURE__*/React.createElement(Line, _extends({
key: index,
gap: size === 'large' ? 3 : size === 'regular' ? 2 : 1,
align: "center",
justify: "center",
fullWidth: true
}, ItemProps, {
className: classNames([staticClassName('SectionCards', theme) && ['amaui-SectionCards-item'], ItemProps?.className, classes.item, classes[`item_size_${size}`]])
}), /*#__PURE__*/React.createElement(Line, _extends({
fullWidth: true
}, item.propsImage, {
className: classNames([staticClassName('SectionCards', theme) && ['amaui-SectionCards-item-image'], item.propsImage?.className, classes.background, item.backgroundImage && styleBackground.backgroundImage && classes.backgroundImage]),
style: _objectSpread({}, styleBackground)
}), urlVideo && /*#__PURE__*/React.createElement("video", {
autoPlay: true,
muted: true,
loop: true,
className: classes.backgroundVideo
}, /*#__PURE__*/React.createElement("source", {
src: urlVideo
})), item.overlay && /*#__PURE__*/React.createElement("div", {
className: classNames([classes.backgroundOverlay, item.overlayBlur && classes.backgroundOverlayBlur]),
style: _objectSpread({}, styleOverlay)
})), /*#__PURE__*/React.createElement(Line, _extends({
gap: 1,
align: "center",
fullWidth: true
}, item.propsMain, {
className: classNames([staticClassName('SectionCards', theme) && ['amaui-SectionCards-item-main'], item.propsMain?.className, classes.main])
}), (item.name || item.description) && /*#__PURE__*/React.createElement(Line, _extends({
gap: 1,
align: "center",
fullWidth: true
}, item.propsWrapperText, {
className: classNames([staticClassName('SectionCards', theme) && ['amaui-SectionCards-item-wrapper-text'], item.propsWrapperText?.className, classes.wrapperText])
}), item.name && /*#__PURE__*/React.createElement(Type, _extends({
version: size === 'large' ? 'h3' : size === 'regular' ? 't1' : 't2',
align: "center",
fullWidth: true,
dangerouslySetInnerHTML: {
__html: textToInnerHTML(item.name)
}
}, item.propsName, {
className: classNames([staticClassName('SectionCards', theme) && ['amaui-SectionCards-item-name'], item.propsName?.className])
})), item.description && /*#__PURE__*/React.createElement(Type, _extends({
version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b3',
priority: "secondary",
align: "center",
fullWidth: true,
dangerouslySetInnerHTML: {
__html: textToInnerHTML(item.description)
}
}, item.propsDescription, {
className: classNames([staticClassName('SectionCards', theme) && ['amaui-SectionCards-item-description'], item.propsDescription?.className])
}))), item.buttonText && /*#__PURE__*/React.createElement(Line, _extends({
align: "center",
fullWidth: true
}, item.propsActions, {
className: classNames([staticClassName('SectionCards', theme) && ['amaui-SectionCards-item-actions'], item.propsActions?.className, classes.actions])
}), /*#__PURE__*/React.createElement(Button, _extends({
version: "filled",
color: "primary",
size: size,
onClick: () => item.to ? navigate(item.to) : window.open(item.link, 'blank')
}, item.propsButton, {
className: classNames([staticClassName('SectionCards', theme) && ['amaui-SectionCards-item-button'], item.propsButton?.className, classes.button])
}), item.buttonText || 'Click here'))));
}, [theme, size]);
return /*#__PURE__*/React.createElement(Section, _extends({
ref: item => {
if (ref) {
if (is('function', ref)) ref(item);else ref.current = item;
}
refs.root.current = item;
},
maxWidth: false,
MainProps: {
justify: 'center',
align: 'center'
},
className: classNames([staticClassName('SectionCards', theme) && ['amaui-SectionCards-root', `amaui-SectionCards-size-${size}`], className, classes.root])
}, other), /*#__PURE__*/React.createElement(Line, _extends({
gap: size === 'large' ? 3.5 : size === 'regular' ? 2.5 : 1.5,
justify: "flex-start",
align: "flex-start",
direction: "row"
}, ItemsProps, {
className: classNames([staticClassName('SectionCards', theme) && ['amaui-SectionCards-items'], ItemsProps?.className, classes.items])
}), values?.map((item, index) => getItem(item, index))));
});
Element.displayName = 'amaui-SectionCards';
export default Element;