import { styled } from 'styled-components';
import { OpizeWrapper, lightSemanticColorPalette } from '../..';
function rgbToHex(rgbString: string): string {
const rgbMatch = rgbString.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
if (!rgbMatch) {
return 'wrongRGB';
}
const toHex = (n: string): string => {
const hex = parseInt(n, 10).toString(16);
return hex.length === 1 ? '0' + hex : hex;
};
return '#' + toHex(rgbMatch[1]) + toHex(rgbMatch[2]) + toHex(rgbMatch[3]);
}
const ColorRows = styled.div`
display: flex;
flex-direction: column;
gap: 24px;
`;
const StyledColorRow = styled.div`
display: flex;
flex-direction: column;
gap: 8px;
`;
const ColorLabel = styled.div`
width: 120px;
font-size: 16px;
font-weight: 600;
`;
const ColorColorsRow = styled.div`
display: flex;
flex-wrap: wrap;
gap: 8px;
`;
const ColorItem = styled.div`
width: 120px;
`;
const ColorPlate = styled.div<{ color: string }>`
width: 100%;
height: 50px;
background-color: ${(props) => props.color};
border-radius: 8px;
margin-bottom: 4px !important;
`;
const ColorName = styled.div`
font-size: 12px !important;
font-weight: 600 !important;
`;
const ColorValue = styled.div`
font-size: 10px !important;
color: rgba(0, 0, 0, 0.4) !important;
`;
function ColorRow({
label,
colors,
}: {
label: React.ReactNode;
colors: { name: string; value: string }[];
}) {
return (
{label}
{colors.map((color) => {
return (
{color.name}
{rgbToHex(color.value)}
);
})}
);
}
export function SemanticColors() {
const colors = Object.entries(lightSemanticColorPalette).map(([key, value]) => ({
name: key,
value: value,
}));
return (
c.name === 'foreground' || c.name === 'background'
)}
/>
c.name.startsWith('primary') || c.name.startsWith('secondary')
)}
/>
c.name.startsWith('statusGray'))}
/>
c.name.startsWith('statusRed'))}
/>
c.name.startsWith('statusYellow'))}
/>
c.name.startsWith('statusGreen'))}
/>
c.name.startsWith('statusBlue'))}
/>
c.name.startsWith('statusViolet'))}
/>
['text', 'link', 'placeholder', 'label'].includes(c.name)
)}
/>
['border', 'background', 'background1'].includes(c.name)
)}
/>
[
'opizeGreen',
'opizeWhite',
'opizeDimWhite',
'c2nViolet',
'c2nBlue',
].includes(c.name)
)}
/>
);
}