Skip to content

Commit

Permalink
feat: css properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kyechan99 committed Mar 11, 2024
1 parent e53c9ff commit 831e6e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/common/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const CardStyled = styled.div<CardProps>`
border-radius: 0.5rem;
background-color: ${({ theme }) => theme.colors.bg};
box-shadow: 0 0 4px ${({ theme }) => theme.colors.gray['300']};
${({ width }) => width && `width: ${width}`}px;
${({ width }) => width && `width: ${width}px`};
`;

export const CardHead = styled.div`
Expand Down
4 changes: 4 additions & 0 deletions src/styles/GlobalStyle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Global, Theme, css } from '@emotion/react';

import { cssCustomProperties } from '@/utils/css';

// import resolveConfigPath, { resolveDefaultConfigPath } from '@/utils/resolve';
import theme from './theme';

const GlobalCustomStyle = (theme: Theme) => css`
Expand All @@ -10,6 +13,7 @@ const GlobalCustomStyle = (theme: Theme) => css`
}
:root {
${cssCustomProperties(theme.colors)}
}
body {
Expand Down
21 changes: 21 additions & 0 deletions src/utils/css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* CSS Variables
* @param obj Theme Data
* @param prefix prefix
* @returns
*/
export const cssCustomProperties = (obj: object, prefix: string = '') => {
let cssString = '';

Object.entries(obj).forEach(([key, value]) => {
const propertyName = prefix ? `${prefix}-${key}` : key;

if (typeof value === 'object') {
cssString += cssCustomProperties(value, propertyName);
} else {
cssString += `--${propertyName}: ${value};\n`;
}
});

return cssString;
};

0 comments on commit 831e6e4

Please sign in to comment.