Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common Styled System props to v6 components #429

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

TyMick
Copy link
Collaborator

@TyMick TyMick commented Jan 6, 2021

I'm running through and adding the common and (when appropriate) typography collections of Styled System props to components as per this comment on #378. Started with Accordion and I'm going to continue down alphabetically. 👍🏼

@TyMick
Copy link
Collaborator Author

TyMick commented Jan 6, 2021

Gave DatePicker a div wrapper in the process, to allow style props to apply to the whole thing. It was only "wrapped" in a React.Fragment before.

DatePicker was previously using colors from "shared-styles".
@TyMick
Copy link
Collaborator Author

TyMick commented Jan 6, 2021

DatePicker was also previously using colors defined in shared-styles instead of using the global Styled System theme, so I changed that as well while I was at it.

@RobertBolender
Copy link
Contributor

Gave DatePicker a div wrapper in the process, to allow style props to apply to the whole thing. It was only "wrapped" in a React.Fragment before.

This is a kind of breaking change, please move this to a v6 version of the component.

TyMick added 5 commits January 8, 2021 15:48
Instead of the old "shared-styles".
And restore the v5 DatePicker to a "legacy" export. This also involved
some adjustments DatePeriodPicker's and DatePickerInput's calls of
DatePicker, since the v6 DatePicker no longer needs to be wrapped.

I also added the Styled System 'layout' props to DatePicker so
DatePickerInput could use a 'width' prop on it.
`width: 100%` and `padding` together were causing the component to
overflow its container on the right side by an amount equal to the sum
of the left and right padding. `box-sizing: border-box` fixes that.
@TyMick
Copy link
Collaborator Author

TyMick commented Jan 8, 2021

One change in c76ca22 (in date-period-picker/styled.jsx) caused a visual change in the component that it seems like was the original intent, just coded incorrectly before. Here's the change:

-import { colors, thickness, fonts } from '../shared-styles';
+import { themeGet } from '@styled-system/theme-get';
 
 ...
 
 export const DatePeriod = styled.div`
-	font: ${fonts.ui14};
+	${themeGet('textStyles.ui.14')}
 	...
 `;
 
 ...
 
 export const Label = styled.label`
 	...
-	font: ${fonts.ui14};
+	${themeGet('textStyles.ui.14')}
 	...
 `;

For context, here's fonts.ui14:

ui14: `
font-size: 14px;
font-weight: normal;
line-height: 14px;
`,

And here's textStyles.ui.14:

'14': {
fontSize: '14px',
lineHeight: '14px',
fontWeight: fontWeights.normal,
},

It's the same set of styles, but since the first version was written font: ${fonts.ui14}; instead of just ${fonts.ui14}, font-weight and line-height were set correctly, but not font-size, since that line ended up in the compiled CSS as font: font-size: 14px;.

Here's a before/after screenshot:

Screen Shot 2021-01-08 at 5 44 54 PM

All this to say, should I leave this at the smaller ui.14 style which seems to have been the original intent, or should I increase it to ui.16 to match the previous actual font size (but also increase the line height by 2 pixels)?

@TyMick TyMick changed the title Add common/typography Styled System props to v6 components Add common Styled System props to v6 components Jan 8, 2021
@RobertBolender
Copy link
Contributor

One change in c76ca22 (in date-period-picker/styled.jsx) caused a visual change in the component that it seems like was the original intent, just coded incorrectly before. Here's the change:

Solid catch.

All this to say, should I leave this at the smaller ui.14 style which seems to have been the original intent, or should I increase it to ui.16 to match the previous actual font size (but also increase the line height by 2 pixels)?

I'll check with our design team, but it can stay at ui.14 for now.

TyMick added 5 commits January 8, 2021 18:22
I started with just Dropdown, as I was intending to add `common` style
props to that family of components. Once I added propTypes for all
Dropdown components, I found that each already accepted `common` props
via one or another component they wrapped.

Adding Dropdown propTypes created the necessity to add propTypes to the
Button components, and in typing the `children` prop of
SegmentedButtonGroup, I decided I wanted to make sure that that
component's children were only `Button`s, so I created a new utility
function: `elementOfType`. I used this function in DropdownMenu's
propTypes as well.

I also added some additional prop types to Popover.
@TyMick
Copy link
Collaborator Author

TyMick commented Jan 9, 2021

I added propTypes to all the Dropdown components in my intent to add common style props to all of them, but once I did so, I found that they already each accepted common props by passing them to Box or Text or something similar.

One probably unexpected addition in baa4444, though, is a new utility function:

import PropTypes from 'prop-types';
/**
* Creates a prop-type-checking function that validates whether the prop value is an element of a
* given component type.
*
* @param {React.ElementType} Component - The component type to check for.
* @returns A PropTypes validation function to use in a component's `propTypes` object.
*/
export function elementOfType(Component) {
// Not very intuitive, but this is the best way to check with PropTypes (see https://github.com/facebook/react/issues/2979)
return PropTypes.shape({
type: PropTypes.oneOf([Component]).isRequired,
});
}

I made it thinking it'd be nice to check component types of children on SegmentedButtonGroup and DropdownMenu. Here's how I'm using it:

SegmentedButtonGroup.propTypes = {
children: PropTypes.arrayOf(elementOfType(Button)).isRequired,

DropdownMenu.propTypes = {
children: PropTypes.arrayOf(
PropTypes.oneOfType([
elementOfType(MenuItem),
elementOfType(MenuItemCheckbox),
elementOfType(MenuItemLink),
elementOfType(MenuItemSeparator),
elementOfType(MenuItemIcon),
elementOfType(MenuItemPrimaryText),
elementOfType(MenuItemSecondaryText),
elementOfType(MenuItemTitle),
]),
).isRequired,

Is that overkill and I should just make those PropTypes.node and call it good?

@RobertBolender
Copy link
Contributor

RobertBolender commented Jan 11, 2021

Is that overkill and I should just make those PropTypes.node and call it good?

No objection to this.

I suppose one soft objection would be that this would start logging warnings for cases where I pass in a wrapped version of one of those components, wouldn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants