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 styles
typing for consumers
#88
Conversation
@jjenzz what do consumers practically get from this? |
@benoitgrelard sorry, should have added this to description: Before: After: |
Right I see, is that because we are expecting users to have to add the styles to the correct parts themselves? |
Yep, or use our extracted css file. The options are as follows: Option oneimport { Button as ButtonPrimitive } from '@interop-ui/react-button';
import '@interop-ui/react-button/styles.css';
export const Button = styled(ButtonPrimitive, {
borderRadius: '3px',
padding: '10px 20px',
}); We have a Option twoimport { Button as ButtonPrimitive, styles } from '@interop-ui/react-button';
export const Button = styled(ButtonPrimitive, {
...styles.button,
borderRadius: '3px',
padding: '10px 20px',
}); |
I think we can probably refactor to something like: const Accordion = props => {
return <div {...interopDataAttrObj<typeof styles>('accordion')} {...props} />
};
export const styles = {
accordion: {}
button: {}
panel: {}
}; and then the extraction script can use I might go through and do that instead. Will be a whole bunch of changes but will be cleaner. |
e6d548a
to
cfdd816
Compare
@@ -290,8 +283,8 @@ interface RadioStaticProps { | |||
Icon: typeof RadioIcon; | |||
} | |||
|
|||
const styles: PrimitiveStyles = { | |||
[interopSelector(ROOT_NAME)]: { | |||
const [styles, interopDataAttrObj] = createStyleObj(RADIO_NAME, (selector) => ({ |
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 one is slightly different and uses a function callback so that we can get the right namespaced selector if we need to reference it in other component 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've removed the need for this in a more recent PR #121
export function createStyleObj<Part extends string = string>( | ||
namespace: string, | ||
originalStyles: | ||
| ((selector: (part: string) => Selector) => PrimitiveStyles<Part>) |
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 can't make this part: Part
here as it becomes part: never
because inference fails
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 removed the need for this in a more recent PR #121
@benoitgrelard @chancestrickland Okay, this is huge now but it's ready. 😬 |
@@ -310,11 +303,11 @@ const styles: PrimitiveStyles = { | |||
zIndex: 1, | |||
opacity: 0, | |||
|
|||
[`&:checked + ${interopDataAttrSelector(ICON_NAME)}`]: { | |||
[`&:checked + ${selector('icon')}`]: { |
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.
Annoyingly the icon
string isn't typed here, it just expects string
. It started to take a while to figure out and since it's only needed in one component, I time-boxed it and failed haha. I'd be surprised if it's possible tbh.
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 remove the need for this in a more recent PR #121
Didn't see any issues at first glance, and typing seems to work as expected. Ran out of time for a thorough review of this one but I may try to look again this weekend if you don't merge before then! |
@chancestrickland @benoitgrelard I'm going to get this in so I can progress in other areas in your absence. Feel free to raise stuff after merge and I'll address 🙂 |
Closes #48
This solution isn't ideal because if a component name changes, we'll have a mismatch between the style object key and the typing if the developer forgets to update thePrimitiveStyles
generic.Unfortunately, my research into how we could handle this a bit better lead me to these two TS tickets which aren't currently possible:Augment Key during Type Mapping microsoft/TypeScript#12754Suggestion: Regex-validated string type microsoft/TypeScript#6579The alternatives I explored all seemed to create too many complex abstractions which became hard to follow. I wanted to get this PR up so it at least works for release and then we can discuss how to solve this in a less human error prone way. It may be okay as is though since these values shouldn't change very often.Any ideas? Solved