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 classNames API and unstyled prop #5457

Merged
merged 12 commits into from
Nov 16, 2022
Merged

Add classNames API and unstyled prop #5457

merged 12 commits into from
Nov 16, 2022

Conversation

nderkim
Copy link
Collaborator

@nderkim nderkim commented Nov 2, 2022

This PR adds the classNames API and the unstyled prop as defined in #5451

I've added storybook stories as examples, but no docs (yet)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 2, 2022

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:

Sandbox Source
react-codesandboxer-example Configuration

@@ -0,0 +1,6 @@
---
'react-select': minor
'@react-select/docs': patch
Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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 to true, but on the inner component it's set to false?
  • 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);
Copy link
Collaborator Author

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',
Copy link
Collaborator Author

@nderkim nderkim Nov 2, 2022

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

Copy link
Owner

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'];
Copy link
Collaborator Author

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

docs/examples/Experimental.tsx Outdated Show resolved Hide resolved
>(
{ theme: { spacing } }: GroupHeadingProps<Option, IsMulti, Group>,
unstyled: boolean
): CSSObjectWithLabel => ({
label: 'group',
color: '#999',
cursor: 'default',
display: 'block',
fontSize: '75%',
fontWeight: 500,
marginBottom: '0.25em',
Copy link
Owner

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-bot
Copy link

changeset-bot bot commented Nov 3, 2022

🦋 Changeset detected

Latest commit: 56a56c4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
react-select Minor
@react-select/docs Patch

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

p > a:visited,
li > a,
li > a:hover,
li > a:visited {
Copy link
Collaborator

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.

@nderkim nderkim force-pushed the alex/with-tailwind branch 2 times, most recently from 7fa19c0 to 0f57c45 Compare November 4, 2022 05:26
@@ -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 },
Copy link
Collaborator

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?)

Copy link
Collaborator Author

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>]: (
Copy link
Collaborator

@lukebennett88 lukebennett88 Nov 7, 2022

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>

Copy link
Collaborator Author

@nderkim nderkim Nov 7, 2022

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.

Copy link
Collaborator

@lukebennett88 lukebennett88 left a 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 👍

@nderkim nderkim merged commit 9289057 into master Nov 16, 2022
@nderkim nderkim deleted the alex/with-tailwind branch November 16, 2022 01:08
@github-actions github-actions bot mentioned this pull request Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants