Skip to content

Commit

Permalink
refactor: update text props and variations
Browse files Browse the repository at this point in the history
  • Loading branch information
abelflopes committed Mar 12, 2024
1 parent 2f5f9c3 commit 24d47d2
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/components/alert/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const Alert = ({
<div {...otherProps} className={classNames(styles.root, styles[skin], className)}>
<div>
{heading ? (
<Text variation="h4" as="p" skin="bold" margin={false} className={styles.heading}>
<Text variation="h4" as="p" skin="bold" margin="none" className={styles.heading}>
{heading}
</Text>
) : null}
Expand Down
6 changes: 3 additions & 3 deletions packages/components/form-field/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ export const FormField = ({
className={styles.label}
skin="bold"
variation="small"
margin={false}
margin="none"
as={<label htmlFor="aaa">{label}</label>}
/>
) : null}

<div className={styles.content}>{children}</div>

{description ? (
<Text className={styles.description} variation="small" margin={false}>
<Text className={styles.description} variation="small" margin="none">
{description}
</Text>
) : null}

{validationMessage ? (
<Text className={styles.validation_message} variation="small" margin={false}>
<Text className={styles.validation_message} variation="small" margin="none">
{validationMessage}
</Text>
) : null}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/modal/src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const Modal = ({
<header
{...props.header}
className={classNames(styles.header, props.header.className)}>
<Text variation="h3" as="p" margin={false}>
<Text variation="h3" as="p" margin="none">
{props.header.heading}
</Text>

Expand Down
8 changes: 3 additions & 5 deletions packages/components/text/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type TextVariation =

export interface TextProps<T extends HTMLTag> extends BaseHTMLProps, ConsumerPolymorphicProps<T> {
/** Adds margin to the text element */
margin?: boolean;
margin?: "default" | "top" | "bottom" | "both" | "none";
/** Specifies the type/visual skin of text element to be rendered */
variation?: TextVariation;
/* Specifies the visual style variations for the text */
Expand All @@ -38,7 +38,7 @@ export interface TextProps<T extends HTMLTag> extends BaseHTMLProps, ConsumerPol

export const Text = <T extends HTMLTag>({
as,
margin = true,
margin = "default",
variation = "p",
skin = "default",
className,
Expand All @@ -54,11 +54,9 @@ export const Text = <T extends HTMLTag>({
classNames(
styles.root,
styles[`variation_${variation}`],
{
[`${styles.margin}`]: margin,
},
computedSkins.filter((skin) => skin !== "inverted").map((skin) => styles[`skin_${skin}`]),
{
[`${styles[`margin_${margin}`]}`]: margin !== "default",
[`${styles.skin_inverted}`]: computedSkins.includes("inverted") || theme.inverted,
},
className,
Expand Down
24 changes: 18 additions & 6 deletions packages/components/text/src/styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ $text-variations: (
h1: (
default: (
font-size: 29px,
font-weight: 500,
font-weight: 600,
line-height: 36px,
),
hover: (),
),
h2: (
default: (
font-size: 24px,
font-weight: 500,
font-weight: 600,
line-height: 36px,
color: get-color(neutral-dark-4),
),
Expand All @@ -77,21 +77,33 @@ $text-variations: (
h3: (
default: (
font-size: 20px,
font-weight: 500,
font-weight: 600,
line-height: 24px,
),
hover: (),
),
h4: (
default: (),
default: (
font-size: 18px,
font-weight: 600,
line-height: 22px,
),
hover: (),
),
h5: (
default: (),
default: (
font-size: 16px,
font-weight: 600,
line-height: 20px,
),
hover: (),
),
h6: (
default: (),
default: (
font-size: 14px,
font-weight: 600,
line-height: 18px,
),
hover: (),
),
p: (
Expand Down
40 changes: 32 additions & 8 deletions packages/components/text/src/styles/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,40 @@

margin-top: get-css-var(text, margin-top);
margin-bottom: get-css-var(text, margin-bottom);
}

&:not(:only-child).margin {
&:not(.p, a) {
@include define-css-var(text, margin-bottom, calc(#{get-css-var(text, font-size)} * 0.75));
}
// Margin

& + & {
@include define-css-var(text, margin-top, get-css-var(text, font-size));
}
}
.h1,
.h2,
.h3,
.h4,
.h5,
.h6 {
@include define-css-var(text, margin-top, get-css-var(text, font-size));
@include define-css-var(text, margin-bottom, calc(#{get-css-var(text, font-size)} * 0.75));
}

.margin_both,
.margin_top,
.variation_p {
@include define-css-var(text, margin-top, get-css-var(text, font-size));
}

.margin_both,
.margin_bottom,
.variation_p {
@include define-css-var(text, margin-bottom, get-css-var(text, font-size));
}

.margin_none,
.margin_top {
@include define-css-var(text, margin-bottom, 0);
}

.margin_none,
.margin_bottom {
@include define-css-var(text, margin-top, 0);
}

// Variation
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/stories/src/text.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export const Inverted: Story = {
},
},
args: {
variation: "inverted",
skin: "inverted",
children: faker.lorem.sentence(),
},
};

export const Link: Story = {
args: {
variation: "link",
skin: "link",
as: <a href="#some-link">{faker.lorem.sentence()}</a>,
},
};

0 comments on commit 24d47d2

Please sign in to comment.