Skip to content

chore: use emotion for styling (pt. 2) #9951

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

Merged
merged 19 commits into from
Oct 2, 2023
Merged

chore: use emotion for styling (pt. 2) #9951

merged 19 commits into from
Oct 2, 2023

Conversation

aslilac
Copy link
Member

@aslilac aslilac commented Sep 29, 2023

Part of #9924
Following #9909

Progress 16_8

From starting with 157 usages of makeStyles across 154 files, this changes brings us down to 132 usages across 129 files.

author Kayla Washburn <mckayla@hey.com> 1696014497 -0600
committer McKayla Washburn <mckayla@hey.com> 1696014979 +0000

parent 4da1223
author Kayla Washburn <mckayla@hey.com> 1696014497 -0600
committer McKayla Washburn <mckayla@hey.com> 1696014955 +0000

parent 4da1223
author Kayla Washburn <mckayla@hey.com> 1696014497 -0600
committer McKayla Washburn <mckayla@hey.com> 1696014933 +0000

parent 4da1223
author Kayla Washburn <mckayla@hey.com> 1696014497 -0600
committer McKayla Washburn <mckayla@hey.com> 1696014828 +0000

refactor: start using emotion for styling (#9909)

get emotional

apologize to the json gods

`make gen`

fix types

this is killing me

fancy `Theme` shenanigans

>:(

caught some mistakes

do a couple more (to fix storybook)

🤬

fix linting
@aslilac aslilac requested review from a team, code-asher, BrunoQuaresma, Kira-Pilot and Parkreiner and removed request for a team and code-asher September 29, 2023 21:45
@aslilac aslilac marked this pull request as ready for review September 29, 2023 22:12
const { isCopied, copy: copyToClipboard } = useClipboard(text);

const fileCopyIconStyles = css`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on these style rules being at the top of the component vs at the bottom?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer to define things top to bottom, but I'm fine with anything.

Another question, though: is there any difference between having the css tag function defined inside the component vs outside?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always put stateful logic (hooks, contexts, queries) at the top of the file while moving CSS to the bottom, but I don't have a strong opinion, just a habit. I'm happy with either. Would be nice to stay consistent either way we go.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I like top-to-bottom. my instinct is always to scroll up for stuff like this, and I'm always a little sad when I realize I was supposed to scroll down. :p

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although that's probably less of an issue here than it was with makeStyles, because "go to definition" will actually work now 🙃

Copy link
Member

@Kira-Pilot Kira-Pilot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!!

Copy link
Member

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Emotion's syntax seems a little more intuitive to me, and I'm happy that it's making the styling more explicit, instead of hiding the details behind a hook

width: theme.spacing(6),
height: theme.spacing(6),
fontSize: theme.spacing(3),
}),
};
} satisfies Record<string, Interpolation<Theme>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the Record be updated to be indexed by type Exclude<AvatarProps["size"], undefined>?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though maybe it'd be better to life the size prop into a separate type, and just reference it in AvatarProps and sizeStyles

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what is cool about satisfies, it doesn't widen the type, it makes sure that T extends Record<...>. if you added an incorrect key here, it would still cause a type error at the lookup, because the keys are still literal types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what is cool about satisfies, it doesn't widen the type, it makes sure that T extends Record<...>. if you added an incorrect key here, it would still cause a type error at the lookup, because TS still knows the actual keys the object has.

Copy link
Member

@Parkreiner Parkreiner Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, you're right that it doesn't widen the type, but I guess the way I look at it is that right now, we have a narrow type, but wide type-checking, when ideally both would be as narrow as possible.

So for this example specifically, there's nothing requiring that all sizes be present in the record – the key for type-checking is any arbitrary string, so TypeScript has no ability to detect typos in key names or forgotten keys. All it knows is that there should be some number of strings in there (including zero)

Like, if we decide to add a "lg" size down the line, there aren't any protections to make sure we don't forget to add a matching style. But with the record being keyed by all members of the union, TypeScript will complain if something doesn't line up

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are! the lookup will fail, we don't need a more stringent satisfies to catch that. it'd just make this type harder to write.

Copy link
Member

@Parkreiner Parkreiner Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, yeah, you're right. I was worried because we don't have the noUncheckedIndexedAccess compiler setting turned on, which can cause issues with trying to read properties from a record, but because it technically isn't a record, and just has the type-checking of one, it's safe.

So we will get errors when trying to consume a property that doesn't exist, instead of weird false positives

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, exactly!

const { isCopied, copy: copyToClipboard } = useClipboard(text);

const fileCopyIconStyles = css`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer to define things top to bottom, but I'm fine with anything.

Another question, though: is there any difference between having the css tag function defined inside the component vs outside?

@aslilac aslilac merged commit 148fa81 into main Oct 2, 2023
@aslilac aslilac deleted the emotional-damage-2 branch October 2, 2023 16:48
@github-actions github-actions bot locked and limited conversation to collaborators Oct 2, 2023
@aslilac aslilac linked an issue Oct 3, 2023 that may be closed by this pull request
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace makeStyles
4 participants