mirror of
https://gh.wpcy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-04-26 18:28:16 +08:00
* add: icon radius component * add: icon radius component * update: add support for widget radius * fix: minor ui fixes * fix: resolve comments * fix: alignment of the icon * update: add styled components * add: corner radius mixpanel event * fix: corner radius should have default values when no value is set based on icon * fix: icon radius input style * add: accessibility attributes * fix: active states color * add: logic to control invalid inputs * update: make aria attributes translatable * update: styled component names * add: spacing between the components
79 lines
1.9 KiB
JavaScript
79 lines
1.9 KiB
JavaScript
import Box from '@elementor/ui/Box';
|
|
import { styled } from '@elementor/ui/styles';
|
|
import { useSettings } from '@ea11y/hooks';
|
|
import { cloneElement } from '@wordpress/element';
|
|
|
|
const WidgetIcon = ({ icon, size, radius, control, type }) => {
|
|
const { iconDesign } = useSettings();
|
|
const strokeColor = `lch(from ${iconDesign?.color || '#2563EB'} calc((50 - l) * 100) 0 0)`;
|
|
let cornerRadius =
|
|
radius || iconDesign?.cornerRadius?.radius + iconDesign?.cornerRadius?.unit;
|
|
let innerRadius =
|
|
radius ||
|
|
iconDesign?.cornerRadius?.radius - 3 + iconDesign?.cornerRadius?.unit;
|
|
let iconSize = size;
|
|
let borderWidth = 1;
|
|
|
|
// Override values for text icon in select control
|
|
if (control === 'select' && type === 'text') {
|
|
cornerRadius = 1;
|
|
innerRadius = 0.5;
|
|
}
|
|
|
|
// Calculate icon size separately for text
|
|
if (control === 'size' && type === 'text') {
|
|
if (size > 50) {
|
|
iconSize = size * 1.2;
|
|
} else {
|
|
iconSize = size * 1;
|
|
}
|
|
}
|
|
|
|
// Calculate border width
|
|
if (size >= 64) {
|
|
borderWidth = 2;
|
|
} else if (size >= 44 && size < 64) {
|
|
borderWidth = 1.5;
|
|
} else {
|
|
borderWidth = 1;
|
|
}
|
|
|
|
return (
|
|
<StyledIconWrapper
|
|
sx={{
|
|
backgroundColor: iconDesign?.color,
|
|
borderRadius: cornerRadius,
|
|
width: 'text' === type ? size * 1.9 : size,
|
|
height: size,
|
|
}}
|
|
>
|
|
<StyledIconInnerWrapper
|
|
sx={{
|
|
border: borderWidth,
|
|
borderColor: strokeColor,
|
|
borderRadius: innerRadius,
|
|
padding: size >= 50 ? '12px' : 1,
|
|
width: 'text' === type ? size * 1.9 - 10 : size - 10,
|
|
height: size - 10,
|
|
}}
|
|
>
|
|
{cloneElement(icon, { size: iconSize / 2.5 })}
|
|
</StyledIconInnerWrapper>
|
|
</StyledIconWrapper>
|
|
);
|
|
};
|
|
|
|
export default WidgetIcon;
|
|
|
|
const StyledIconWrapper = styled(Box)`
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
padding: ${({ theme }) => theme.spacing(1)};
|
|
`;
|
|
|
|
const StyledIconInnerWrapper = styled(Box)`
|
|
display: inline-flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
`;
|