kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Break Counter into its own component
rodzic
d56a97451f
commit
aa9c643006
|
@ -6,7 +6,7 @@ import { spring } from 'react-motion';
|
||||||
import Overlay from 'react-overlays/lib/Overlay';
|
import Overlay from 'react-overlays/lib/Overlay';
|
||||||
import { withRouter, RouteComponentProps } from 'react-router-dom';
|
import { withRouter, RouteComponentProps } from 'react-router-dom';
|
||||||
|
|
||||||
import { IconButton } from 'soapbox/components/ui';
|
import { IconButton, Counter } from 'soapbox/components/ui';
|
||||||
import SvgIcon from 'soapbox/components/ui/icon/svg-icon';
|
import SvgIcon from 'soapbox/components/ui/icon/svg-icon';
|
||||||
import Motion from 'soapbox/features/ui/util/optional_motion';
|
import Motion from 'soapbox/features/ui/util/optional_motion';
|
||||||
|
|
||||||
|
@ -196,8 +196,8 @@ class DropdownMenu extends React.PureComponent<IDropdownMenu, IDropdownMenuState
|
||||||
<span className='truncate'>{text}</span>
|
<span className='truncate'>{text}</span>
|
||||||
|
|
||||||
{count ? (
|
{count ? (
|
||||||
<span className='ml-auto h-5 w-5 flex-none block px-1.5 py-0.5 bg-accent-500 text-xs text-white rounded-full ring-2 ring-white'>
|
<span className='ml-auto h-5 w-5 flex-none'>
|
||||||
{count}
|
<Counter count={count} />
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import Icon from 'soapbox/components/icon';
|
import Icon from 'soapbox/components/icon';
|
||||||
import { shortNumberFormat } from 'soapbox/utils/numbers';
|
import { Counter } from 'soapbox/components/ui';
|
||||||
|
|
||||||
interface IIconWithCounter extends React.HTMLAttributes<HTMLDivElement> {
|
interface IIconWithCounter extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
count: number,
|
count: number,
|
||||||
|
@ -14,9 +14,11 @@ const IconWithCounter: React.FC<IIconWithCounter> = ({ icon, count, ...rest }) =
|
||||||
<div className='relative'>
|
<div className='relative'>
|
||||||
<Icon id={icon} {...rest} />
|
<Icon id={icon} {...rest} />
|
||||||
|
|
||||||
{count > 0 && <i className='absolute -top-2 -right-2 block px-1.5 py-0.5 bg-accent-500 text-xs text-white rounded-full ring-2 ring-white'>
|
{count > 0 && (
|
||||||
{shortNumberFormat(count)}
|
<i className='absolute -top-2 -right-2'>
|
||||||
</i>}
|
<Counter count={count} />
|
||||||
|
</i>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ import classNames from 'classnames';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { NavLink } from 'react-router-dom';
|
import { NavLink } from 'react-router-dom';
|
||||||
|
|
||||||
import { Icon, Text } from './ui';
|
import { Icon, Text, Counter } from './ui';
|
||||||
|
|
||||||
interface ISidebarNavigationLink {
|
interface ISidebarNavigationLink {
|
||||||
count?: number,
|
count?: number,
|
||||||
|
@ -44,8 +44,8 @@ const SidebarNavigationLink = React.forwardRef((props: ISidebarNavigationLink, r
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{withCounter && count > 0 ? (
|
{withCounter && count > 0 ? (
|
||||||
<span className='absolute -top-2 -right-2 block px-1.5 py-0.5 bg-accent-500 text-xs text-white rounded-full ring-2 ring-white'>
|
<span className='absolute -top-2 -right-2'>
|
||||||
{count}
|
<Counter count={count} />
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { shortNumberFormat } from 'soapbox/utils/numbers';
|
||||||
|
|
||||||
|
interface ICounter {
|
||||||
|
count: number,
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A simple counter for notifications, etc. */
|
||||||
|
const Counter: React.FC<ICounter> = ({ count }) => {
|
||||||
|
return (
|
||||||
|
<span className='block px-1.5 py-0.5 bg-accent-500 text-xs text-white rounded-full ring-2 ring-white'>
|
||||||
|
{shortNumberFormat(count)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Counter;
|
|
@ -1,7 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import Counter from '../counter/counter';
|
||||||
|
|
||||||
import SvgIcon from './svg-icon';
|
import SvgIcon from './svg-icon';
|
||||||
|
|
||||||
|
|
||||||
interface IIcon extends Pick<React.SVGAttributes<SVGAElement>, 'strokeWidth'> {
|
interface IIcon extends Pick<React.SVGAttributes<SVGAElement>, 'strokeWidth'> {
|
||||||
className?: string,
|
className?: string,
|
||||||
count?: number,
|
count?: number,
|
||||||
|
@ -13,8 +16,8 @@ interface IIcon extends Pick<React.SVGAttributes<SVGAElement>, 'strokeWidth'> {
|
||||||
const Icon = ({ src, alt, count, size, ...filteredProps }: IIcon): JSX.Element => (
|
const Icon = ({ src, alt, count, size, ...filteredProps }: IIcon): JSX.Element => (
|
||||||
<div className='relative' data-testid='icon'>
|
<div className='relative' data-testid='icon'>
|
||||||
{count ? (
|
{count ? (
|
||||||
<span className='absolute -top-2 -right-3 block px-1.5 py-0.5 bg-accent-500 text-xs text-white rounded-full ring-2 ring-white'>
|
<span className='absolute -top-2 -right-3'>
|
||||||
{count}
|
<Counter count={count} />
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ export { default as Avatar } from './avatar/avatar';
|
||||||
export { default as Button } from './button/button';
|
export { default as Button } from './button/button';
|
||||||
export { Card, CardBody, CardHeader, CardTitle } from './card/card';
|
export { Card, CardBody, CardHeader, CardTitle } from './card/card';
|
||||||
export { default as Column } from './column/column';
|
export { default as Column } from './column/column';
|
||||||
|
export { default as Counter } from './counter/counter';
|
||||||
export { default as Emoji } from './emoji/emoji';
|
export { default as Emoji } from './emoji/emoji';
|
||||||
export { default as EmojiSelector } from './emoji-selector/emoji-selector';
|
export { default as EmojiSelector } from './emoji-selector/emoji-selector';
|
||||||
export { default as Form } from './form/form';
|
export { default as Form } from './form/form';
|
||||||
|
|
|
@ -9,6 +9,8 @@ import classNames from 'classnames';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
|
import Counter from '../counter/counter';
|
||||||
|
|
||||||
import './tabs.css';
|
import './tabs.css';
|
||||||
|
|
||||||
const HORIZONTAL_PADDING = 8;
|
const HORIZONTAL_PADDING = 8;
|
||||||
|
@ -132,8 +134,8 @@ const Tabs = ({ items, activeItem }: ITabs) => {
|
||||||
>
|
>
|
||||||
<div className='relative'>
|
<div className='relative'>
|
||||||
{count ? (
|
{count ? (
|
||||||
<span className='absolute -top-2 left-full ml-1 block px-1.5 py-0.5 bg-accent-500 text-xs text-white rounded-full ring-2 ring-white'>
|
<span className='absolute -top-2 left-full ml-1'>
|
||||||
{count}
|
<Counter count={count} />
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue