Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed example/public/fonts/slack-icons-Regular.eot
Binary file not shown.
Binary file removed example/public/fonts/slack-icons-Regular.ttf
Binary file not shown.
Binary file removed example/public/fonts/slack-icons-Regular.woff
Binary file not shown.
13 changes: 10 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ import {
SlackCounter,
SlackSelector,
YoutubeCounter,
} from '@charkour/react-reactions';
} from '../../src';
import React from 'react';
import './App.css';

const styles = {
addStyle: {
paddingLeft: '4px',
opacity: '1',
},
};

async function getFileFromUrl(
url: string,
name: string,
Expand All @@ -36,7 +43,7 @@ const App: React.FC = () => {
'readme.md'
);
read.readAsBinaryString(file);
read.onloadend = function () {
read.onloadend = function() {
setMarkdown(read.result as string);
console.log(read.result);
};
Expand Down Expand Up @@ -82,7 +89,7 @@ const App: React.FC = () => {
<YoutubeCounter />
<FacebookCounter />
<PokemonCounter />
<SlackCounter />
<SlackCounter styles={styles} />
</div>
</>
);
Expand Down
72 changes: 49 additions & 23 deletions src/components/slack/SlackCounter.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import React from 'react';
import React, { CSSProperties } from 'react';
import { CounterObject, groupBy, Hover, HoverStyle } from '../../helpers';
import SlackCounterGroup from './SlackCounterGroup';
import SlackCSS from './SlackCSS';

export interface styleProps {
addStyle?: CSSProperties;
counterStyle?: CSSProperties;
groupStyle?: CSSProperties;
addStyleHover?: CSSProperties;
}
export interface SlackCounterProps {
counters?: CounterObject[];
user?: string;
onSelect?: (emoji: string) => void;
onAdd?: () => void;
styles?: styleProps;
}
const deepMerge = (a: styleProps, b: styleProps, fn: any) =>
// @ts-ignore
[...new Set([...Object.keys(a), ...Object.keys(b)])].reduce(
// @ts-ignore
(acc, key) => ({ ...acc, [key]: fn(key, a[key], b[key]) }),
{}
);

export const SlackCounter = React.forwardRef<HTMLDivElement, SlackCounterProps>(
(
Expand All @@ -17,21 +31,27 @@ export const SlackCounter = React.forwardRef<HTMLDivElement, SlackCounterProps>(
user = defaultProps.user,
onSelect = defaultProps.onSelect,
onAdd = defaultProps.onAdd,
styles,
},
ref
) => {
const groups = groupBy(counters, 'emoji');

const mergedStyles: styleProps = deepMerge(
defaultProps.styles,
styles || {},
(key: any, a: any, b: any) =>
key === 'a' ? a && b : Object.assign({}, a, b)
);
return (
<>
<SlackCSS />
<Hover ref={ref} style={counterStyle}>
<Hover ref={ref} style={mergedStyles.counterStyle}>
{Object.keys(groups).map((emoji: string) => {
const names = groups[emoji].map(({ by }: CounterObject) => {
return by;
});
return (
<div style={groupStyle} key={emoji}>
<div style={mergedStyles.groupStyle} key={emoji}>
<SlackCounterGroup
emoji={emoji}
count={names.length}
Expand All @@ -43,8 +63,8 @@ export const SlackCounter = React.forwardRef<HTMLDivElement, SlackCounterProps>(
);
})}
<HoverStyle
hoverStyle={addStyleHover}
style={addStyle}
hoverStyle={mergedStyles.addStyleHover || {}}
style={mergedStyles.addStyle}
onClick={onAdd}
>
<SlackCounterGroup emoji={''} />
Expand All @@ -55,6 +75,23 @@ export const SlackCounter = React.forwardRef<HTMLDivElement, SlackCounterProps>(
}
);

const counterStyle = {
display: 'flex',
};
const addStyle = {
cursor: 'pointer',
fontFamily: 'Slack',
paddingLeft: '8px',
opacity: '0',
transition: 'opacity 0.1s ease-in-out',
};
const groupStyle = {
marginRight: '4px',
};
const addStyleHover = {
opacity: '1',
};

export const defaultProps: Required<SlackCounterProps> = {
counters: [
{
Expand All @@ -73,23 +110,12 @@ export const defaultProps: Required<SlackCounterProps> = {
onAdd: () => {
console.log('add');
},
};

const counterStyle = {
display: 'flex',
};
const addStyle = {
cursor: 'pointer',
fontFamily: 'Slack',
paddingLeft: '8px',
opacity: '0',
transition: 'opacity 0.1s ease-in-out',
};
const groupStyle = {
marginRight: '4px',
};
const addStyleHover = {
opacity: '1',
styles: {
counterStyle,
addStyle,
groupStyle,
addStyleHover,
},
};

export default SlackCounter;
Loading