Skip to content

Commit

Permalink
feat(odyssey-react): unset default text properties in Box using false…
Browse files Browse the repository at this point in the history
… value for props
  • Loading branch information
andrewberg-okta committed Dec 14, 2021
1 parent da68956 commit d0ba167
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
49 changes: 26 additions & 23 deletions packages/odyssey-react/src/components/Box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import {
withStyles,
PolymorphicForwardRef,
toPascalCase,
toCamelCase,
} from "../../utils";
import styles from "./Box.module.scss";
import textStyles from "../Text/Text.module.scss";

type spacing = "xs" | "s" | "m" | "l" | "xl";
type spacing = "xs" | "s" | "m" | "l" | "xl" | "0" | false;
type overflow = "visible" | "hidden" | "clip" | "scroll" | "auto";
type borderRadius = "base" | "outer" | "none";

Expand Down Expand Up @@ -143,6 +144,7 @@ export interface BoxProps {
maxHeight?: "screen" | "screen-minus-padding";
/**
* Margin applied outside the box border
* @default "0"
*/
margin?: spacing | spacing[];
/**
Expand All @@ -163,6 +165,7 @@ export interface BoxProps {
marginLeft?: spacing;
/**
* Padding applied inside the box between the border and the content
* @default "0"
*/
padding?: spacing | spacing[];
/**
Expand Down Expand Up @@ -299,29 +302,29 @@ export interface BoxProps {
userSelect?: "none" | "text" | "contain" | "all" | "auto";
/**
* Whether to apply the body text color class
* @default true
* @default body
*/
applyColor?: boolean;
color?: "body" | false;
/**
* Whether to apply the normal font weight class
* @default true
* @default regular
*/
applyFontWeight?: boolean;
fontWeight?: "regular" | false;
/**
* Whether to apply the normal font style class
* @default true
* @default normal
*/
applyFontStyle?: boolean;
fontStyle?: "normal" | false;
/**
* Whether to apply the base font size class
* @default true
* @default base
*/
applyFontSize?: boolean;
fontSize?: "base" | false;
/**
* Whether to apply the base line height class
* @default true
* @default normal
*/
applyLineHeight?: boolean;
lineHeight?: "normal" | false;
}

/**
Expand All @@ -331,11 +334,11 @@ let Box = forwardRef(
(
{
as = "div",
applyColor = true,
applyFontWeight = true,
applyFontStyle = true,
applyFontSize = true,
applyLineHeight = true,
color = "body",
fontWeight = "regular",
fontStyle = "normal",
fontSize = "base",
lineHeight = "normal",
display,
position,
flexDirection,
Expand All @@ -352,12 +355,12 @@ let Box = forwardRef(
maxWidth,
height,
maxHeight,
margin,
margin = "0",
marginTop,
marginRight,
marginBottom,
marginLeft,
padding,
padding = "0",
paddingTop,
paddingRight,
paddingBottom,
Expand Down Expand Up @@ -540,11 +543,11 @@ let Box = forwardRef(
cursor && styles[`cursor${toPascalCase(cursor)}`],
pointerEvents && styles[`pointerEvents${toPascalCase(pointerEvents)}`],
userSelect && styles[`userSelect${toPascalCase(userSelect)}`],
applyColor && textStyles.bodyColor,
applyFontWeight && textStyles.regularWeight,
applyFontStyle && textStyles.normalStyle,
applyFontSize && textStyles.baseSize,
applyLineHeight && textStyles.normalLineHeight,
color && textStyles[`${toCamelCase(color)}Color`],
fontWeight && textStyles[`${toCamelCase(fontWeight)}Weight`],
fontStyle && textStyles[`${toCamelCase(fontStyle)}Style`],
fontSize && textStyles[`${toCamelCase(fontSize)}Size`],
lineHeight && textStyles[`${toCamelCase(lineHeight)}LineHeight`],
className
);

Expand Down
4 changes: 4 additions & 0 deletions packages/odyssey-react/src/components/Box/_box-margin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/

/* stylelint-disable property-disallowed-list */
.margin0 {
margin: 0;
}

.marginXs {
margin: $spacing-xs;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/odyssey-react/src/components/Box/_box-padding.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/

/* stylelint-disable property-disallowed-list */
.padding0 {
padding: 0;
}

.paddingXs {
padding: $spacing-xs;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/odyssey-react/src/components/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ let Text = forwardRef((props, ref) => {
{...omitProps}
ref={ref}
className={componentClass}
applyColor={false}
applyFontWeight={false}
applyFontStyle={false}
applyFontSize={false}
applyLineHeight={false}
color={false}
fontWeight={false}
fontStyle={false}
fontSize={false}
lineHeight={false}
children={children}
/>
);
Expand Down
8 changes: 8 additions & 0 deletions packages/odyssey-storybook/src/components/Box/Box.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ export const MarginPadding = (): ReactElement => (
<>
Margin
<Box display="flex" alignItems="flex-end">
<Box backgroundColor="danger-light" marginRight="s">
<Box borderColor="ui" backgroundColor="default">
&nbsp;default / 0&nbsp;
</Box>
</Box>
<Box backgroundColor="danger-light" marginRight="s">
<Box borderColor="ui" backgroundColor="default" margin="xs">
&nbsp;xs&nbsp;
Expand Down Expand Up @@ -219,6 +224,9 @@ export const MarginPadding = (): ReactElement => (
</Box>
Padding
<Box display="flex" alignItems="flex-end">
<Box backgroundColor="success-light" borderColor="ui" marginRight="s">
<Box backgroundColor="default">&nbsp;default / 0&nbsp;</Box>
</Box>
<Box
padding="xs"
backgroundColor="success-light"
Expand Down

0 comments on commit d0ba167

Please sign in to comment.