Skip to content

Commit da6b156

Browse files
committed
Update Paragraph
- force mt to override the default spacing - add paragraphMarginBetween to the theme - remove unused "skipMarginTop" prop
1 parent 2e11cec commit da6b156

File tree

7 files changed

+24
-20
lines changed

7 files changed

+24
-20
lines changed

src/components/Field/Debug.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ function FieldDebug(props: Props) {
2121
return (
2222
<Box as="code" bg="gray.50" {...getDataAttributes('FieldDebug')} display="block" padding="md">
2323
{objectEntries(props)
24-
.filter(([key]) => key !== 'debug')
24+
.filter(([key]) => !['debug', 'theme'].includes(key))
2525
.sort(sortByLocaleCompare('0'))
2626
.map(([key, value]) => (
27-
<Paragraph key={key} skipMarginTop>
27+
<Paragraph key={key} mt="xxs">
2828
<b>{key}</b>: {primitiveToString(value, key)}
2929
</Paragraph>
3030
))}

src/components/Paragraph/Paragraph.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { forwardRef, isValidElement } from 'react';
22
import { css } from '@emotion/react';
33
import styled from '@emotion/styled';
44
import { omit, px } from '@gilbarbara/helpers';
5+
import is from 'is-lite';
56

67
import { alignStyles, getStyledOptions, getStyles } from '~/modules/system';
78

@@ -17,18 +18,23 @@ export const StyledParagraph = styled('p', getStyledOptions())<ParagraphProps &
1718
marginTop: 0,
1819
},
1920
props => {
20-
const { skipMarginTop, theme } = props;
21+
const { mt, theme } = props;
22+
let marginTop: string | undefined;
23+
24+
if (mt && mt !== 'auto') {
25+
marginTop = px(theme.spacing[mt]);
26+
} else if (is.number(mt)) {
27+
marginTop = px(mt);
28+
}
2129

2230
return css`
23-
${getStyles(omit(props, 'align'), { useFontSize: true })};
31+
${getStyles(omit(props, 'align', 'mt'), { useFontSize: true })};
2432
${alignStyles(props)};
33+
margin-top: ${marginTop} !important;
2534
26-
${!skipMarginTop &&
27-
css`
28-
& + & {
29-
margin-top: ${px(theme.spacing.sm)};
30-
}
31-
`};
35+
& + p {
36+
margin-top: ${px(theme.paragraphMarginBetween)};
37+
}
3238
`;
3339
},
3440
);

src/components/Paragraph/useParagraph.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,11 @@ export interface ParagraphKnownProps
2121
WithChildren,
2222
Pick<WithColors, 'color'>,
2323
WithMargin,
24-
WithTextOptions {
25-
/**
26-
* Skip the top margin for adjacent paragraphs.
27-
* @default false
28-
*/
29-
skipMarginTop?: boolean;
30-
}
24+
WithTextOptions {}
3125

3226
export const defaultProps = {
33-
skipMarginTop: false,
3427
...textDefaultOptions,
35-
};
28+
} satisfies Omit<ParagraphProps, 'children'>;
3629

3730
export function useParagraph(props: ParagraphProps) {
3831
return useComponentProps(props, defaultProps);

src/hooks/__snapshots__/useTheme.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ exports[`useTheme > should return properly 1`] = `
173173
"outlineOpacity": 0.6,
174174
"outlineWidth": 3,
175175
"outlineZIndex": 10,
176+
"paragraphMarginBetween": "12px",
176177
"radius": {
177178
"full": "9999px",
178179
"lg": "24px",

src/modules/__snapshots__/helpers.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ exports[`mergeTheme > should return a modified theme 1`] = `
200200
"outlineOpacity": 0.6,
201201
"outlineWidth": 3,
202202
"outlineZIndex": 10,
203+
"paragraphMarginBetween": "12px",
203204
"radius": {
204205
"full": "9999px",
205206
"lg": "24px",
@@ -683,6 +684,7 @@ exports[`mergeTheme > should return the default theme 1`] = `
683684
"outlineOpacity": 0.6,
684685
"outlineWidth": 3,
685686
"outlineZIndex": 10,
687+
"paragraphMarginBetween": "12px",
686688
"radius": {
687689
"full": "9999px",
688690
"lg": "24px",

src/modules/theme.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ export const inputPaddingY = {
405405
lg: spacing.md,
406406
};
407407

408+
export const paragraphMarginBetween = spacing.sm;
409+
408410
export const selectPaddingY = {
409411
sm: spacing.xxs,
410412
md: spacing.xs,

stories/Overview/components/Spacing.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function Spacing() {
1212
The <strong>spacing</strong> key is used used for margin, padding and a few other
1313
attributes.
1414
</Paragraph>
15-
<Paragraph skipMarginTop>
15+
<Paragraph mt="xxs">
1616
Most components supports the margin and/or padding props where you can pass a spacing key.
1717
</Paragraph>
1818
<Paragraph mt="md">Additionally, you can use these shortcuts:</Paragraph>

0 commit comments

Comments
 (0)