Skip to content

Commit

Permalink
feat: added Tag component
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed May 3, 2020
1 parent 75dee54 commit e9c6691
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
16 changes: 4 additions & 12 deletions ui/blocks/src/StorySource/StorySource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { jsx } from 'theme-ui';
import { FC, useState, useContext } from 'react';
import { getControlValue } from '@component-controls/core';
import { Styled } from 'theme-ui';
import { transparentize } from 'polished';
import {
ThemeContext,
Source,
SourceProps,
ActionItem,
Tag,
} from '@component-controls/components';
import { repositoryActions } from '../utils/repositoryActions';
import {
Expand Down Expand Up @@ -123,24 +123,16 @@ export const StorySource: FC<StorySourceProps> = ({

return splitToken.map((s: string) =>
s.trim().length ? (
<span
<Tag
{...getTokenProps({ token, key })}
sx={{
display: 'inline-block',
//@ts-ignore
backgroundColor: transparentize(0.8, color),
paddingLeft: 1,
paddingRight: 1,
//@ts-ignore
border: `1px solid ${color}`,
}}
color={color}
>
{controls &&
viewStyle === 'values' &&
param.type === 'usage'
? getControlValue(controls, s) || s
: s}
</span>
</Tag>
) : (
s
),
Expand Down
17 changes: 17 additions & 0 deletions ui/components/src/Tag/Tag.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { Tag, TagProps } from './Tag';

export default {
title: 'Components/Tag',
component: Tag,
};

export const overview = ({ color }: TagProps) => {
return <Tag color={color}>some text</Tag>;
};

overview.story = {
controls: {
color: { type: 'color', value: 'red' },
},
};
26 changes: 26 additions & 0 deletions ui/components/src/Tag/Tag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @jsx jsx */
/* eslint react/jsx-key: 0 */
import { jsx } from 'theme-ui';
import { FC } from 'react';
import { transparentize } from 'polished';

export interface TagProps {
color: string;
}

export const Tag: FC<TagProps> = ({ children, color, ...rest }) => (
<span
{...rest}
sx={{
display: 'inline-block',
//@ts-ignore
backgroundColor: transparentize(0.8, color),
paddingLeft: 1,
paddingRight: 1,
//@ts-ignore
border: `1px solid ${color}`,
}}
>
{children}
</span>
);
1 change: 1 addition & 0 deletions ui/components/src/Tag/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Tag';
1 change: 1 addition & 0 deletions ui/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './Source';
export * from './Subtitle';
export * from './Table';
export * from './Tabs';
export * from './Tag';
export * from './ThemeContext';
export * from './Title';
export * from './Toggle';
Expand Down

0 comments on commit e9c6691

Please sign in to comment.