Skip to content

Commit

Permalink
chore: add BulletSeparator story
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jan 25, 2024
1 parent 6489805 commit 2fa66e1
Show file tree
Hide file tree
Showing 12 changed files with 477 additions and 322 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@
"@sentry/webpack-plugin": "2.10.2",
"@stacks/connect-react": "22.2.0",
"@stacks/stacks-blockchain-api-types": "6.3.4",
"@storybook/addon-essentials": "7.6.7",
"@storybook/addon-interactions": "7.6.7",
"@storybook/addon-links": "7.6.7",
"@storybook/addon-essentials": "7.6.10",
"@storybook/addon-interactions": "7.6.10",
"@storybook/addon-links": "7.6.10",
"@storybook/addon-onboarding": "1.0.10",
"@storybook/blocks": "7.6.7",
"@storybook/react": "7.6.7",
"@storybook/react-webpack5": "7.6.7",
"@storybook/test": "7.6.7",
"@storybook/blocks": "7.6.10",
"@storybook/react": "7.6.10",
"@storybook/react-webpack5": "7.6.10",
"@storybook/test": "7.6.10",
"@types/argon2-browser": "1.18.2",
"@types/chroma-js": "2.4.1",
"@types/chrome": "0.0.246",
Expand Down Expand Up @@ -319,7 +319,7 @@
"react-refresh": "0.14.0",
"schema-inspector": "2.0.2",
"speed-measure-webpack-plugin": "1.5.0",
"storybook": "7.6.7",
"storybook": "7.6.10",
"stream-browserify": "3.0.0",
"svg-url-loader": "8.0.0",
"ts-node": "10.9.2",
Expand Down
6 changes: 3 additions & 3 deletions src/app/components/account/account-list-item-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { SettingsSelectors } from '@tests/selectors/settings.selectors';
import { Flex, HStack, Stack, StackProps, styled } from 'leather-styles/jsx';

import { useViewportMinWidth } from '@app/common/hooks/use-media-query';
import { BulletSeparator } from '@app/ui/components/bullet-separator/bullet-separator';
import { CheckmarkIcon } from '@app/ui/components/icons/checkmark-icon';
import { Spinner } from '@app/ui/components/spinner';
import { truncateMiddle } from '@app/ui/utils/truncate-middle';

import { CaptionDotSeparator } from '../caption-dot-separator';
import { Flag } from '../layout/flag';
import { StacksAccountLoader } from '../loaders/stacks-account-loader';
import { BitcoinNativeSegwitAccountLoader } from './bitcoin-account-loader';
Expand Down Expand Up @@ -65,7 +65,7 @@ export function AccountListItemLayout(props: AccountListItemLayoutProps) {
)}
</HStack>
<HStack alignItems="center" gap="space.02" whiteSpace="nowrap">
<CaptionDotSeparator>
<BulletSeparator>
<StacksAccountLoader index={index}>
{account => (
<styled.span textStyle="caption.02">
Expand All @@ -81,7 +81,7 @@ export function AccountListItemLayout(props: AccountListItemLayoutProps) {
</styled.span>
)}
</BitcoinNativeSegwitAccountLoader>
</CaptionDotSeparator>
</BulletSeparator>
</HStack>
</Stack>
</Flag>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import {
} from '@app/query/bitcoin/ordinals/inscription.hooks';
import { useGetInscriptionsByOutputQuery } from '@app/query/bitcoin/ordinals/inscriptions-by-param.query';
import { useCurrentAccountNativeSegwitAddressIndexZero } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks';
import { BulletSeparator } from '@app/ui/components/bullet-separator/bullet-separator';
import { BtcIcon } from '@app/ui/components/icons/btc-icon';

import { CaptionDotSeparator } from '../caption-dot-separator';
import { TransactionItemLayout } from '../transaction-item/transaction-item.layout';
import { BitcoinTransactionCaption } from './bitcoin-transaction-caption';
import { BitcoinTransactionIcon } from './bitcoin-transaction-icon';
Expand Down Expand Up @@ -79,12 +79,12 @@ export function BitcoinTransactionItem({ transaction, ...rest }: BitcoinTransact
isOriginator && !transaction.status.confirmed && !containsTaprootInput(transaction);

const txCaption = (
<CaptionDotSeparator>
<BulletSeparator>
<BitcoinTransactionCaption>{caption}</BitcoinTransactionCaption>
{inscriptionData ? (
<BitcoinTransactionCaption>{inscriptionData.mime_type}</BitcoinTransactionCaption>
) : null}
</CaptionDotSeparator>
</BulletSeparator>
);
const txValue = <BitcoinTransactionValue>{value}</BitcoinTransactionValue>;

Expand Down
22 changes: 0 additions & 22 deletions src/app/components/caption-dot-separator.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Flex, HStack, styled } from 'leather-styles/jsx';

import { BulletOperator } from '@app/ui/components/bullet-separator/bullet-separator';
import { InfoIcon } from '@app/ui/components/icons/info-icon';
import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip';

Expand All @@ -14,7 +15,7 @@ export function AssetCaption({ caption, isUnanchored }: AssetCaptionProps) {
{isUnanchored ? (
<>
<styled.span mx="space.01" textStyle="caption.02">
Microblock
<BulletOperator /> Microblock
</styled.span>
<BasicTooltip side="right" label={'Learn more about microblocks'}>
<HStack>
Expand Down
6 changes: 3 additions & 3 deletions src/app/features/asset-list/components/stacks-asset-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { styled } from 'leather-styles/jsx';

import { useStxBalance } from '@app/common/hooks/balance/stx/use-stx-balance';
import { ftDecimals } from '@app/common/stacks-utils';
import { CaptionSeparatorDot } from '@app/components/caption-dot-separator';
import { CryptoCurrencyAssetItem } from '@app/components/crypto-assets/crypto-currency-asset/crypto-currency-asset-item';
import { StxAvatar } from '@app/components/crypto-assets/stacks/components/stx-avatar';
import { useStacksFungibleTokenAssetBalancesAnchoredWithMetadata } from '@app/query/stacks/balance/stacks-ft-balances.hooks';
import { StacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.models';
import { BulletOperator } from '@app/ui/components/bullet-separator/bullet-separator';
import { Caption } from '@app/ui/components/typography/caption';

import { StacksFungibleTokenAssetList } from './stacks-fungible-token-asset-list';
Expand All @@ -24,14 +24,14 @@ export function StacksAssetList({ account }: StacksAssetListProps) {

const stxAdditionalBalanceInfo = stxLockedBalance?.amount.isGreaterThan(0) ? (
<styled.span>
<CaptionSeparatorDot mr="space.01" pos="relative" top="-2px" />
<BulletOperator mr="space.01" pos="relative" />
{ftDecimals(stxLockedBalance.amount, stxLockedBalance.decimals || 0)} locked
</styled.span>
) : undefined;

const stxAdditionalUsdBalanceInfo = stxLockedBalance?.amount.isGreaterThan(0) ? (
<Caption ml="4px">
<CaptionSeparatorDot mr="space.01" pos="relative" top="-1px" />
<BulletOperator mr="space.01" pos="relative" />
{stxUsdLockedBalance} locked
</Caption>
) : undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Box, Flex, HStack, Stack } from 'leather-styles/jsx';
import { RouteUrls } from '@shared/route-urls';
import { noop } from '@shared/utils';

import { CaptionDotSeparator } from '@app/components/caption-dot-separator';
import { usePressable } from '@app/components/item-hover';
import { Flag } from '@app/components/layout/flag';
import { StatusPending } from '@app/components/status-pending';
Expand All @@ -21,6 +20,7 @@ import {
PendingBrc20Transfer,
usePendingBrc20Transfers,
} from '@app/store/ordinals/ordinals.slice';
import { BulletSeparator } from '@app/ui/components/bullet-separator/bullet-separator';
import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip';
import { Caption } from '@app/ui/components/typography/caption';

Expand Down Expand Up @@ -128,7 +128,7 @@ function PendingBrcTransfer({ order }: PendingBrcTransferProps) {
{order.amount} {order.tick}
</>
<HStack width="100%" mt="space.02">
<CaptionDotSeparator>
<BulletSeparator>
<Flex>
<Flag
ml="space.02"
Expand All @@ -139,7 +139,7 @@ function PendingBrcTransfer({ order }: PendingBrcTransferProps) {
<StatusLabel status={order.status} />
</Flag>
</Flex>
</CaptionDotSeparator>
</BulletSeparator>
</HStack>
{component}
</Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Meta, StoryObj } from '@storybook/react';

import { Caption } from '../typography/caption';
import { Title } from '../typography/title';
import { BulletSeparator as Component } from './bullet-separator';

/**
* Note that the BulletSeparator component doesn't bring it's own margins, these
* should be appiled separately
*/
const meta: Meta<typeof Component> = {
component: Component,
tags: ['autodocs'],
title: 'BulletSeparator',
};

export default meta;
type Story = StoryObj<typeof Component>;

export const BulletSeparator: Story = {
render: () => (
<Component>
<span style={{ margin: '0 8px' }}>Item 1</span>
<span style={{ margin: '0 8px' }}>Item 2</span>
<span style={{ margin: '0 8px' }}>Item 3</span>
</Component>
),
};

export const WithCaption: Story = {
render: () => (
<Caption>
<Component>
<span style={{ margin: '0 6px' }}>Item 1</span>
<span style={{ margin: '0 6px' }}>Item 2</span>
<span style={{ margin: '0 6px' }}>Item 3</span>
</Component>
</Caption>
),
};

export const WithTitle: Story = {
render: () => (
<Title>
<Component>
<span style={{ margin: '0 6px' }}>Item 1</span>
<span style={{ margin: '0 6px' }}>Item 2</span>
<span style={{ margin: '0 6px' }}>Item 3</span>
</Component>
</Title>
),
};
32 changes: 32 additions & 0 deletions src/app/ui/components/bullet-separator/bullet-separator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { cloneElement, isValidElement } from 'react';

import { Circle, CircleProps } from 'leather-styles/jsx';

export function BulletOperator(props: CircleProps) {
return (
<Circle
display="inline-block"
verticalAlign="middle"
backgroundColor="currentColor"
size="3px"
// Visual adjustment for correct centering on retina displays
transform="translateY(-0.5px)"
{...props}
/>
);
}

interface BulletSeparatorSeparatorProps {
children: React.ReactNode;
}
export function BulletSeparator({ children }: BulletSeparatorSeparatorProps) {
const parsedChildren = Array.isArray(children) ? children : [children];
const content = parsedChildren
.flatMap((child, index) => {
if (!isValidElement(child)) return null;
return [cloneElement(child, { key: index }), <BulletOperator key={index + 'dot'} />];
})
.filter(val => val !== null)
.slice(0, -1);
return <>{content}</>;
}
1 change: 1 addition & 0 deletions src/app/ui/components/tabs/tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const meta: Meta<typeof Component.Root> = {
};

export default meta;

type Story = StoryObj<typeof Component.Root>;

export const Tabs: Story = {
Expand Down
8 changes: 1 addition & 7 deletions src/app/ui/components/typography/caption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import { forwardRef } from 'react';
import { BoxProps, styled } from 'leather-styles/jsx';

export const Caption = forwardRef<HTMLSpanElement, BoxProps>(({ children, ...props }, ref) => (
<styled.span
color="accent.text-subdued"
display="block"
ref={ref}
textStyle="caption.02"
{...props}
>
<styled.span color="accent.text-subdued" ref={ref} textStyle="caption.02" {...props}>
{children}
</styled.span>
));
Loading

0 comments on commit 2fa66e1

Please sign in to comment.