Skip to content

Commit

Permalink
fix: rename ColorSwatch
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Sep 10, 2020
1 parent f45c523 commit 7a0d4fa
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
16 changes: 0 additions & 16 deletions ui/design-tokens/src/ColorBlock/ColorBlock.stories.tsx

This file was deleted.

16 changes: 16 additions & 0 deletions ui/design-tokens/src/ColorSwatch/ColorBlock.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { ColorSwatch, ColorBlockProps } from './ColorSwatch';

export default {
title: 'Design Tokens/ColorSwatch',
component: ColorSwatch,
};

export const overview = ({ name, color }: ColorBlockProps) => (
<ColorSwatch name={name} color={color} />
);

overview.controls = {
name: { type: 'text' },
color: { type: 'color', value: '#fbce4a' },
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
/** @jsx jsx */
import { FC } from 'react';
import { jsx, Box, Theme } from 'theme-ui';
import { parseToRgb } from 'polished';
import { parseToRgb, rgbToColorString } from 'polished';

export interface ColorBlockProps {
name?: string;
color: string;
}

export const ColorBlock: FC<ColorBlockProps> = ({ name, color }) => {
const hex = color;
const rgb = parseToRgb(color);
export const ColorSwatch: FC<ColorBlockProps> = ({ name, color }) => {
const colorStr = color.toLowerCase().startsWith('rgb')
? rgbToColorString(parseToRgb(color))
: color;
const hex = colorStr.startsWith('#') ? colorStr : `#${colorStr}`;
const rgb = parseToRgb(hex);
return (
<Box sx={{ display: 'flex', flexDirection: 'row', width: '220px' }}>
<Box sx={{ bg: color, width: 64, height: 64 }}></Box>
<Box
sx={{
bg: color,
width: 64,
height: 64,
border: (t: Theme) => ` 1px solid ${t.colors?.shadow}`,
}}
></Box>
<Box
sx={{
display: 'flex',
Expand All @@ -28,6 +38,7 @@ export const ColorBlock: FC<ColorBlockProps> = ({ name, color }) => {
sx={{
fontWeight: 'bold',
borderBottom: (t: Theme) => ` 1px solid ${t.colors?.shadow}`,
pb: 1,
}}
>
{name || hex}
Expand Down
1 change: 1 addition & 0 deletions ui/design-tokens/src/ColorSwatch/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ColorSwatch';
1 change: 1 addition & 0 deletions ui/design-tokens/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ColorSwatch';

0 comments on commit 7a0d4fa

Please sign in to comment.