@onesy/ui-react
Version:
UI for React
268 lines (267 loc) • 12 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
const _excluded = ["ref", "size", "values", "responsive", "fullHeight", "ItemProps", "CarouselProps", "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 { useNavigate } from 'react-router-dom';
import { is, isEnvironment, textToInnerHTML } from '@onesy/utils';
import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react';
import SectionElement from '../Section/Section';
import ButtonElement from '../Button';
import CarouselElement from '../Carousel';
import LineElement from '../Line';
import TypeElement from '../Type';
import useMediaQuery from '../useMediaQuery';
import { staticClassName } from '../utils';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const useStyle = styleMethod(theme => ({
root: {},
size_small: {
'&.onesy-Carousel-root': {
height: '340px'
}
},
size_regular: {
'&.onesy-Carousel-root': {
height: '540px'
}
},
size_large: {
'&.onesy-Carousel-root': {
height: '740px'
}
},
fullHeight: {
'&.onesy-Carousel-root': {
height: '100vh'
}
},
main: {
padding: '0 96px !important',
zIndex: '14 !important'
},
item: {
position: 'relative',
height: '100%'
},
item_size_small: {
padding: `${theme.methods.space.value(3, 'px')} ${theme.methods.space.value(3, 'px')}`
},
item_size_regular: {
padding: `${theme.methods.space.value(6.75, 'px')} ${theme.methods.space.value(3, 'px')}`
},
item_size_large: {
padding: `${theme.methods.space.value(9.25, 'px')} ${theme.methods.space.value(3, 'px')}`
},
text: {
'&.onesy-Type-root': {
color: 'white !important',
mixBlendMode: 'difference'
}
},
button: {
transition: theme.methods.transitions.make('transform'),
'&:active': {
transform: 'scale(0.94)'
}
},
background: {
position: 'absolute',
inset: '0',
overflow: 'hidden',
zIndex: '1'
},
backgroundImage: {
backgroundSize: 'cover !important',
backgroundPosition: 'center !important',
backgroundRepeat: 'no-repeat !important'
},
backgroundVideo: {
position: 'absolute',
inset: '0',
minHeight: '100%',
minWidth: '100%',
top: '50%',
transform: 'translateY(-50%)',
zIndex: '1'
},
backgroundOverlay: {
position: 'absolute',
inset: '0'
},
backgroundOverlayBlur: {
backdropFilter: 'blur(12px)'
},
'@media only screen and (max-width: 640px)': {
$main: {
paddingInline: 72
}
}
}), {
name: 'onesy-SectionCarousel'
});
const Element = props_ => {
const theme = useOnesyTheme();
const l = theme.l;
const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesySectionCarousel?.props?.default), props_);
const Line = theme?.elements?.Line || LineElement;
const Section = theme?.elements?.Section || SectionElement;
const Button = theme?.elements?.Button || ButtonElement;
const Carousel = theme?.elements?.Carousel || CarouselElement;
const Type = theme?.elements?.Type || TypeElement;
const {
ref,
size: size_ = 'regular',
values: values_ = [],
responsive = true,
fullHeight,
ItemProps,
CarouselProps,
className
} = props,
other = _objectWithoutProperties(props, _excluded);
const {
classes
} = useStyle();
const navigate = isEnvironment('browser') && useNavigate();
const refs = {
root: React.useRef(undefined)
};
const laptop = useMediaQuery('(max-width: 1440px)', {
element: refs.root.current
});
const mobile = useMediaQuery('(max-width: 768px)', {
element: refs.root.current
});
let size = size_;
if (responsive) {
if (laptop) size = 'regular';else if (mobile) size = 'small';
}
// Max 4
const values = values_?.slice(0, 4);
const getItem = (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_0 = 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), 0.74) : palette_0?.main
});
}
const urlVideo = item.backgroundVideo?.url || item.backgroundVideo?.urlSmall || (is('string', item.backgroundVideo) ? item.backgroundVideo : '');
return /*#__PURE__*/_jsx(Section, _objectSpread(_objectSpread({
size: size,
gap: 0,
align: "flex-start",
justify: "center",
fullWidth: true
}, ItemProps), {}, {
className: classNames([staticClassName('SectionCarousel', theme) && ['onesy-SectionCarousel-item'], ItemProps?.className, classes.item, classes[`item_size_${size}`]]),
children: /*#__PURE__*/_jsxs(Line, {
gap: 1,
align: "flex-start",
justify: "center",
fullWidth: true,
className: classNames([staticClassName('SectionCarousel', theme) && ['onesy-SectionCarousel-item-main'], classes.main, classes.background, item.backgroundImage && styleBackground.backgroundImage && classes.backgroundImage]),
style: _objectSpread({}, styleBackground),
children: [urlVideo && /*#__PURE__*/_jsx("video", {
autoPlay: true,
muted: true,
loop: true,
className: classNames([staticClassName('SectionCarousel', theme) && ['onesy-SectionCarousel-item-background-video'], classes.backgroundVideo]),
children: /*#__PURE__*/_jsx("source", {
src: urlVideo
})
}), item.overlay && /*#__PURE__*/_jsx("div", {
className: classNames([staticClassName('SectionCarousel', theme) && ['onesy-SectionCarousel-item-background-overlay'], classes.backgroundOverlay, item.overlayBlur && classes.backgroundOverlayBlur]),
style: _objectSpread({}, styleOverlay)
}), item.name && /*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({
version: size === 'large' ? 'd1' : size === 'regular' ? 'd2' : 'd3',
fullWidth: true,
dangerouslySetInnerHTML: {
__html: textToInnerHTML(item.name)
}
}, item.propsName), {}, {
className: classNames([staticClassName('SectionCarousel', theme) && ['onesy-SectionCarousel-item-name'], item.propsName?.className, classes.text])
})), item.description && /*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({
version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b2',
fullWidth: true,
dangerouslySetInnerHTML: {
__html: textToInnerHTML(item.description)
}
}, item.propsDescription), {}, {
className: classNames([staticClassName('SectionCarousel', theme) && ['onesy-SectionCarousel-item-description'], item.propsDescription?.className, classes.text])
})), item.buttonText && /*#__PURE__*/_jsx(Line, _objectSpread(_objectSpread({
direction: "row",
align: "center",
justify: "flex-start",
fullWidth: true
}, item.propsButtonWrapper), {}, {
style: _objectSpread({
marginTop: 12
}, item.propsButtonWrapper?.style),
children: /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({
version: "filled",
color: "primary",
size: size === 'large' ? 'regular' : size === 'regular' ? 'small' : 'small',
onClick: () => item.to ? navigate(item.to) : window.open(item.link, 'blank')
}, item.propsButton), {}, {
className: classNames([staticClassName('SectionCarousel', theme) && ['onesy-SectionCarousel-item-button'], item.propsButton?.className, classes.button]),
children: item.buttonText || l('Click here')
}))
}))]
})
}), index);
};
return /*#__PURE__*/_jsx(Section, _objectSpread(_objectSpread({
ref: item_0 => {
if (ref) {
if (is('function', ref)) ref(item_0);else ref.current = item_0;
}
refs.root.current = item_0;
},
maxWidth: false,
padding: !values?.length,
className: classNames([staticClassName('SectionCarousel', theme) && ['onesy-SectionCarousel-root', `onesy-SectionCarousel-size-${size}`], className, classes.root])
}, other), {}, {
children: !!values?.length && /*#__PURE__*/_jsx(Carousel, _objectSpread(_objectSpread({
items: values?.map((item_1, index_0) => getItem(item_1, index_0)),
autoPlay: true
}, CarouselProps), {}, {
className: classNames([staticClassName('SectionCarousel', theme) && ['onesy-SectionCarousel-items'], CarouselProps?.className, classes.items, classes[`size_${size}`], fullHeight && classes.fullHeight])
}))
}));
};
Element.displayName = 'onesy-SectionCarousel';
export default Element;