Skip to content

Commit

Permalink
Add CssVariableColorSwatch column to CSS variables list
Browse files Browse the repository at this point in the history
  • Loading branch information
timkrins committed Mar 3, 2024
1 parent 7b1457f commit cc6a5e8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { ColorSwatch } from '@mantine/core';

const colorVariableRegex = /^(var\(--mantine-color[\w-]+\)|#\w+|rgba?\(\w+\))$/gm;

export interface CssVariableColorSwatchProps {
variable: string;
}

export function CssVariableColorSwatch({ variable }: CssVariableColorSwatchProps) {
if (!variable || !variable.match(colorVariableRegex)) {
return null;
}

return <ColorSwatch size={20} color={variable} />;
}
4 changes: 4 additions & 0 deletions docs/src/components/CssVariablesList/CssVariablesList.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import React from 'react';
import { Code, DEFAULT_THEME, defaultCssVariablesResolver, keys } from '@mantine/core';
import { MdxDataTable, MdxTitle } from '../MdxProvider';
import { CssVariableColorSwatch } from './CssVariableColorSwatch/CssVariableColorSwatch';

export function CssVariablesList() {
const resolvedVariables = defaultCssVariablesResolver(DEFAULT_THEME);
const variables = keys(resolvedVariables.variables).map((key) => [
<Code style={{ whiteSpace: 'nowrap' }}>{key}</Code>,
resolvedVariables.variables[key],
<CssVariableColorSwatch variable={resolvedVariables.variables[key]} />,
]);

const lightVariables = keys(resolvedVariables.light).map((key) => [
<Code style={{ whiteSpace: 'nowrap' }}>{key}</Code>,
resolvedVariables.light[key],
<CssVariableColorSwatch variable={resolvedVariables.light[key]} />,
]);

const darkVariables = keys(resolvedVariables.dark).map((key) => [
<Code style={{ whiteSpace: 'nowrap' }}>{key}</Code>,
resolvedVariables.dark[key],
<CssVariableColorSwatch variable={resolvedVariables.dark[key]} />,
]);

return (
Expand Down

0 comments on commit cc6a5e8

Please sign in to comment.