diff --git a/package.json b/package.json index c8bf0a3..2fad092 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "size": "size-limit", "analyze": "size-limit --why", "storybook": "start-storybook -p 6006", - "build-storybook": "build-storybook" + "build-storybook": "build-storybook", + "new": "chmod +x ./scripts/new.sh; ./scripts/new.sh" }, "peerDependencies": { "react": ">=16" diff --git a/scripts/new.sh b/scripts/new.sh new file mode 100755 index 0000000..246fb9a --- /dev/null +++ b/scripts/new.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +mkdir ./src/$1 + +echo "" > ./src/$1/index.tsx +echo "" > ./src/$1/props.tsx +echo "" > ./src/$1/stories.tsx +echo "" > ./src/$1/styles.tsx +echo "" > ./src/$1/.test.tsx \ No newline at end of file diff --git a/src/Dot/.test.tsx b/src/Dot/.test.tsx new file mode 100644 index 0000000..1ce0a01 --- /dev/null +++ b/src/Dot/.test.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import * as ReactDOM from 'react-dom'; +import { Default as Thing } from './stories'; + +describe('Thing', () => { + it('renders without crashing', () => { + const div = document.createElement('div'); + ReactDOM.render(, div); + ReactDOM.unmountComponentAtNode(div); + }); +}); diff --git a/src/Dot/index.tsx b/src/Dot/index.tsx new file mode 100644 index 0000000..c99a5e9 --- /dev/null +++ b/src/Dot/index.tsx @@ -0,0 +1,30 @@ +import React from 'react'; +import { stringToColor } from '../util/colorMapping'; +import { Props } from './props'; +import { styles } from './styles'; + +export const Dot = ({ + avatarUrl = undefined, + username = '', + style = {}, + visible = true +}: Props) => { + + const color = stringToColor(username) + + return ( +
+ ) +} \ No newline at end of file diff --git a/src/Dot/props.tsx b/src/Dot/props.tsx new file mode 100644 index 0000000..8f6343b --- /dev/null +++ b/src/Dot/props.tsx @@ -0,0 +1,8 @@ +import CSS from 'csstype'; + +export interface Props { + avatarUrl?: string; + username?: string; + style?: CSS.Properties; + visible?: boolean; +} \ No newline at end of file diff --git a/src/Dot/stories.tsx b/src/Dot/stories.tsx new file mode 100644 index 0000000..17a658e --- /dev/null +++ b/src/Dot/stories.tsx @@ -0,0 +1,34 @@ +import React from 'react'; + +import { Meta, Story } from '@storybook/react'; + +import { Dot } from '.'; +import { Props } from './props'; + +const meta: Meta = { + title: 'Dot', + component: Dot, + argTypes: { + onClick: { control: '' } + } +} + +export default meta; + +const Template: Story = ({ avatarUrl, username, style, visible }) => ( + +); + +export const Default = Template.bind({}); +Default.args = { + avatarUrl: 'https://chat-engine-assets.s3.amazonaws.com/tutorials/my-face-min.png', + username: 'Dylan', + style: { float: 'right', marginLeft: '4px' } +}; + +export const NoAvatarUrl = Template.bind({}); +NoAvatarUrl.args = { + avatarUrl: undefined, + username: 'Dylan', + style: { float: 'right', marginLeft: '4px' } +}; \ No newline at end of file diff --git a/src/Dot/styles.tsx b/src/Dot/styles.tsx new file mode 100644 index 0000000..fb6e3cd --- /dev/null +++ b/src/Dot/styles.tsx @@ -0,0 +1,15 @@ +import { Properties } from 'csstype'; + +export const styles = { + default: { + borderRadius: '13px', + textAlign: 'center', + backgroundRepeat: 'no-repeat', + backgroundPosition: 'center', + backgroundSize: '14px', + // CSS Transitions + transition: "all .33s ease", + WebkitTransition: "all .33s ease", + MozTransition: "all .33s ease", + } as Properties +}; \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx index ce5a214..f13682c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,3 +1,4 @@ export * from './Button'; export * from './Input'; export * from './ChatCard'; +export * from './Dot'; \ No newline at end of file diff --git a/src/util/colorMapping.ts b/src/util/colorMapping.ts new file mode 100644 index 0000000..1800a48 --- /dev/null +++ b/src/util/colorMapping.ts @@ -0,0 +1,36 @@ +const colors = [ + '#D64045', + '#5B3000', + '#00CC99', + '#467599', + '#1D3354', + '#8F250C', + '#6153CC', + '#961D4E', + '#A29F15', + '#0CAADC', + '#FF5154', + '#FA7921', + '#688E26', + '#550527', + '#A10702', + '#FF1053', + '#6C6EA0', + '#100B00', +] + +const stringToNumber = (str: string) => { + let sum = 0 + for (var i = 0; i < str.length; i++) { + sum = sum + (str.charCodeAt(i) * i) - 97 + } + return sum +} + +export const stringToColor = (str: string) => { + if (!str) { + return 'black' + } else { + return colors[stringToNumber(str) % colors.length] + } +} \ No newline at end of file