-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 classNames
API and unstyled
prop
#5457
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 56a56c4:
|
@@ -0,0 +1,6 @@ | |||
--- | |||
'react-select': minor | |||
'@react-select/docs': patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we version docs? Should this be minor
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No one is consuming the docs as a package, so I probably wouldn't even worry about versioning it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed it's at version 3.1.2
though, and no idea how it got there 🤷
@@ -1078,11 +1093,16 @@ export default class Select< | |||
key: Key, | |||
props: StylesProps<Option, IsMulti, Group>[Key] | |||
) => { | |||
const base = defaultStyles[key](props as any); | |||
const { unstyled } = this.props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made unstyled
only available on the parent component (for now) because:
- It minimises the scope of this PR
- What happens if
unstyled
on the parent component is set totrue
, but on the inner component it's set tofalse
? - We can easily add it to the inner components later. If we added it now, and decided to change it later, it would be a breaking change.
getClassName = <Key extends keyof StylesProps<Option, IsMulti, Group>>( | ||
key: Key, | ||
props: StylesProps<Option, IsMulti, Group>[Key] | ||
) => this.props.classNames[key]?.(props as any); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typing issue here (pre-existing) that I'm ignoring for now to keep the scope of this PR down
>( | ||
{ theme: { spacing } }: GroupHeadingProps<Option, IsMulti, Group>, | ||
unstyled: boolean | ||
): CSSObjectWithLabel => ({ | ||
label: 'group', | ||
color: '#999', | ||
cursor: 'default', | ||
display: 'block', | ||
fontSize: '75%', | ||
fontWeight: 500, | ||
marginBottom: '0.25em', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't (yet) looked too deeply into why some of these values are hardcoded, so i'm keeping them in the "permanent" section of the styles
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was a mistake from when groups got added, they should be using theme variables. If you can line them up with existing theme values, please do 🙏
@@ -101,6 +103,7 @@ interface GroupHeadingPropsDefinedProps< | |||
selectProps: Props<Option, IsMulti, Group>; | |||
theme: Theme; | |||
getStyles: GetStyles<Option, IsMulti, Group>; | |||
getClassName: CommonProps<Option, IsMulti, Group>['getClassName']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why these types are re-defined here, but just following the existing pattern to simplify this PR
>( | ||
{ theme: { spacing } }: GroupHeadingProps<Option, IsMulti, Group>, | ||
unstyled: boolean | ||
): CSSObjectWithLabel => ({ | ||
label: 'group', | ||
color: '#999', | ||
cursor: 'default', | ||
display: 'block', | ||
fontSize: '75%', | ||
fontWeight: 500, | ||
marginBottom: '0.25em', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was a mistake from when groups got added, they should be using theme variables. If you can line them up with existing theme values, please do 🙏
🦋 Changeset detectedLatest commit: 56a56c4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
6f00114
to
b07f568
Compare
p > a:visited, | ||
li > a, | ||
li > a:hover, | ||
li > a:visited { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a quick and dirty fix for some links being styled differently in the docs.
Fixing it properly would be more work and not sure how long for this world the existing docs site is.
7fa19c0
to
0f57c45
Compare
@@ -105,8 +105,7 @@ const Heading = (props: HeadingProps) => { | |||
store.add(nodeKey, { key: nodeKey, label, level, path: `#${slug}` }); | |||
} | |||
const css = { | |||
marginTop: 0, | |||
'&:not(:first-of-type)': { marginTop: 30 }, | |||
'&:first-child': { marginTop: 0 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason behind changing this (other than simplifying things?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the previous style would result in:
// 0
<h1/>
// 0
<h2/>
// 0
<h3/>
// 30
<h2/>
// 30
<h3/>
but i think the intention was to just do:
// 0
<h1/>
<h2/>
<h3/>
<h2/>
<h3/>
GroupBase<unknown> | ||
> = { | ||
export const defaultStyles: { | ||
[K in keyof StylesProps<any, any, any>]: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: instead of using any
, could we instead not pass a generic here, and provide default values to StylesProps
instead? e.g. something like this?
export interface StylesProps<
- Option,
- IsMulti extends boolean,
- Group extends GroupBase<Option>
+ Option = unknown,
+ IsMulti extends boolean = boolean,
+ Group extends GroupBase<Option> = GroupBase<Option>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was intentional to show that it doesn't matter what we pass in because we are only using the keys, which are unaffected by the generics.
I'd prefer not to use defaults if possible because it just opens up the opportunity to be less explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments, but this LGTM 👍
bbfdb5e
to
56a56c4
Compare
This PR adds the
classNames
API and theunstyled
prop as defined in #5451I've added
storybook
stories as examples, but no docs (yet)