Replies: 1 comment 3 replies
-
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There’s been a discussion on Slack regarding Typescript syntax, adding it here so we have a paper trail in the repo for future generations.
Example of inline types
The consensus was that it looks messy
Type object
Real world example
Some important things to note is that in this example we don’t use destructuring in function arguments or inline type definition.
This is the proposed solution in the Divider pr. Missing return value, see next point.
Update 31.08.2020
With the above syntax default props has to be repeated both in the js-doc comments and the desctructuring of the props object to be picked up by docgen:
The reason for this is that we don’t actually set the default in the function parameters, but in the destructuring afterwards so in order for docgen to be able to extract the defaults the following syntax must be used instead, even though it might be argued that it’s less legible.
Return value
Pros: The advantage of adding return values is to avoid errors if the developer forgets to return something, and also to avoid void as the return value.
Cons: The drawback of using return value is that prettier inserts a line-break. We can increase the print-width to avoid that to a certain extent – but that would potentially reformat a lot of files. Besides, the return value is inferred anyway so it might not be needed.
Decision: Unclear about this one
Style props
In #700 we use
type StyledProps = Pick<Props, 'maxWidth'>
to pick one of the props to use in the styled component. This is something that should be investigated further and potentially be used across all components.Extending props
In some components we use
type Props = React.HTMLAttributes<HTMLDivElement>
, in otherstype Props = JSX.IntrinsicElements['nav']
. This is something we need to investigate and decide on one of them. There’s a vast number of discussions online about this subject.Types for tokens
Several components(like Button, Banner, Cards) are updated to use the ComponentToken. This is a mechanism to ensure that the components are as similar as possible.
ComponentToken
States
States are representation of states in Figma, which are in turn inspired from states in material design.
Entities
If a component has sub parts, add them in a
entities
object.Color & Variants
If a component has different colors (like
info
,warning
,success
orerror
) or variants (likecontained
,outlined
,ghost
orghost_icon
) we export multiple token constants.Beta Was this translation helpful? Give feedback.
All reactions