Skip to content

Commit 77bf929

Browse files
DateDetails: allow setting of text size and weight (#658)
1 parent 6392877 commit 77bf929

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

src/components/DateDetails/DateDetails.stories.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ export default {
2828
type: "select",
2929
},
3030
},
31+
size: {
32+
control: {
33+
type: "select",
34+
},
35+
options: ["xs", "sm", "md", "lg"],
36+
},
37+
weight: {
38+
control: {
39+
type: "select",
40+
},
41+
options: ["normal", "medium", "semibold", "bold", "mono"],
42+
},
3143
},
3244
component: DateDetails,
3345
title: "Display/DateDetails",
@@ -47,7 +59,9 @@ export const Playground = {
4759
<DateDetails
4860
date={date}
4961
side={args.side}
62+
size={args.size}
5063
systemTimeZone={args.systemTimeZone}
64+
weight={args.weight}
5165
/>
5266
);
5367
},

src/components/DateDetails/DateDetails.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Text } from "@/components/Typography/Text/Text";
1313
import { linkStyles, StyledLinkProps } from "@/components/Link/common";
1414
import { GridContainer } from "@/components/GridContainer/GridContainer";
1515
import { Container } from "@/components/Container/Container";
16+
import { TextSize, TextWeight } from "../commonTypes";
1617

1718
dayjs.extend(advancedFormat);
1819
dayjs.extend(duration);
@@ -106,10 +107,18 @@ export type ArrowPosition = "top" | "right" | "left" | "bottom";
106107
export interface DateDetailsProps {
107108
date: Date;
108109
side?: ArrowPosition;
110+
size?: TextSize;
109111
systemTimeZone?: string;
112+
weight?: TextWeight;
110113
}
111114

112-
export const DateDetails = ({ date, side = "top", systemTimeZone }: DateDetailsProps) => {
115+
export const DateDetails = ({
116+
date,
117+
side = "top",
118+
size = "sm",
119+
systemTimeZone,
120+
weight = "normal",
121+
}: DateDetailsProps) => {
113122
const dayjsDate = dayjs(date);
114123

115124
let systemTime;
@@ -127,7 +136,12 @@ export const DateDetails = ({ date, side = "top", systemTimeZone }: DateDetailsP
127136
$size="sm"
128137
$weight="medium"
129138
>
130-
<Text size="sm">{dayjs.utc(date).fromNow()}</Text>
139+
<Text
140+
size={size}
141+
weight={weight}
142+
>
143+
{dayjs.utc(date).fromNow()}
144+
</Text>
131145
</UnderlinedTrigger>
132146
<Popover.Content
133147
side={side}

src/components/Link/Link.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
} from "react";
99
import { Icon, IconName } from "@/components";
1010
import { styled } from "styled-components";
11-
import { linkStyles, TextSize, TextWeight } from "./common";
11+
import { linkStyles } from "./common";
12+
import { TextSize, TextWeight } from "../commonTypes";
1213

1314
export interface LinkProps<T extends ElementType = "a"> {
1415
size?: TextSize;

src/components/Link/common.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { css } from "styled-components";
2-
3-
export type TextSize = "xs" | "sm" | "md" | "lg";
4-
export type TextWeight = "normal" | "medium" | "semibold" | "bold";
2+
import { TextSize, TextWeight } from "../commonTypes";
53

64
export type StyledLinkProps = { $size: TextSize; $weight: TextWeight };
75

src/components/Typography/Text/Text.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import {
66
forwardRef,
77
} from "react";
88
import { styled } from "styled-components";
9+
import { TextSize, TextWeight } from "@/components/commonTypes";
910

1011
export type TextAlignment = "left" | "center" | "right";
1112
export type TextColor = "default" | "muted" | "danger" | "disabled";
12-
export type TextSize = "xs" | "sm" | "md" | "lg";
13-
export type TextWeight = "normal" | "medium" | "semibold" | "bold" | "mono";
1413

1514
export interface TextProps<T extends ElementType = "p"> {
1615
children: ReactNode;

src/components/commonTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type TextSize = "xs" | "sm" | "md" | "lg";
2+
export type TextWeight = "normal" | "medium" | "semibold" | "bold" | "mono";

0 commit comments

Comments
 (0)