docs(custom-components): adding initial guide for creating custom components#517
docs(custom-components): adding initial guide for creating custom components#517
Conversation
Codecov Report
@@ Coverage Diff @@
## master #517 +/- ##
=======================================
Coverage 88.17% 88.17%
=======================================
Files 42 42
Lines 1455 1455
Branches 212 187 -25
=======================================
Hits 1283 1283
Misses 167 167
Partials 5 5Continue to review full report at Codecov.
|
docs/src/views/CustomComponents.tsx
Outdated
| ].join('\n')} | ||
| /> | ||
|
|
||
| <p>Let's go step by step throughout all bits from the renderComponent method.</p> |
There was a problem hiding this comment.
-> renderComponentcreateComponent
I also changed this in the CHANGELOG.md file that seems to mention renderComponent as well
https://github.com/stardust-ui/react/pull/518/files#r235773446
docs/src/views/CustomComponents.tsx
Outdated
| const componentProps = _.pick(props, 'children') | ||
| return <button className={cx(props.className, classes.root)} {...componentProps} /> | ||
| }, | ||
| }) |
There was a problem hiding this comment.
I think that we should omit the usage of lodash in such basic examples:
const StyledButton: React.SFC<StyledButtonProps> = createComponent<StyledButtonProps, {}>({
displayName: 'StyledButton',
render({ className, stardust, ...props }) {
const { classes } = stardust
return <button {...rest} className={cx(className, classes.root)} />
},
})As I see, my code does the same thing or no?
There was a problem hiding this comment.
We are applying in this case the styles and variables to the button, but I get your point, will change it not to use lodash.
There was a problem hiding this comment.
Something like this?
const StyledButton: React.SFC<StyledButtonProps> = createComponent<StyledButtonProps, {}>({
displayName: 'StyledButton',
render({ stardust, className, children }) {
const { classes } = stardust
const componentProps = { children }
return <button className={cx(className, classes.root)} {...componentProps} />
},
})There was a problem hiding this comment.
-return <button className={cx(className, classes.root)} {...componentProps} />
+return <button className={cx(className, classes.root)}>{children}</button>👍
docs/src/views/CustomComponents.tsx
Outdated
| }) | ||
|
|
||
| export default () => ( | ||
| <DocPage title="Custom Components"> |
There was a problem hiding this comment.
maybe something like "Integrate Custom Components" - because currently this is not absolutely clear from header whether we are suggesting to develop custom components or integrate existing ones
docs/src/views/CustomComponents.tsx
Outdated
| <DocPage title="Custom Components"> | ||
| <Header as="h2" content="Overview" /> | ||
| <p> | ||
| You can use your own components as part of the Stardust's theming mechanism. In order for all |
docs/src/views/CustomComponents.tsx
Outdated
| value={[ | ||
| `import { createComponent } from '@stardust-ui/react'`, | ||
| ``, | ||
| `export interface StyledButtonProps {`, |
There was a problem hiding this comment.
I would suggest to remove TS from this example - main reason is that it introduces quite a lot of 'noise', and additional one (and the one that applies to broader community) is that our docs should be readable for folks that have no prior knowledge of TS
docs/src/views/CustomComponents.tsx
Outdated
| </p> | ||
|
|
||
| <p> | ||
| The first argument to the <code>createComponent</code> config's param is the displayName. This |
There was a problem hiding this comment.
would suggest to also wrap displayName and Provider in <code/>
docs/src/views/CustomComponents.tsx
Outdated
|
|
||
| <p> | ||
| The first argument to the <code>createComponent</code> config's param is the displayName. This | ||
| name is very important, because that's the key that will be used in the Provider's theme if |
There was a problem hiding this comment.
we could simplify this sentence a bit:
is the displayName, which value might be used as key to define component's styles and variables in theme, exactly the same way how it might be done for any first-class Stardust component.
I think that this will provide enough thrill to the reader, so one will fully understand the importance of this prop ;)
docs/src/views/CustomComponents.tsx
Outdated
| `<Provider`, | ||
| ` theme={{`, | ||
| ` componentStyles: {`, | ||
| ` StyledButton: {`, |
There was a problem hiding this comment.
would suggest to swap variables and styles sections, as the later one uses data defined in former.
docs/src/views/CustomComponents.tsx
Outdated
| /> | ||
|
|
||
| <p> | ||
| The second argument of the <code>createComponent</code> config param is the render method. |
There was a problem hiding this comment.
lets wrap render in <code> as well
docs/src/views/CustomComponents.tsx
Outdated
|
|
||
| <p> | ||
| The second argument of the <code>createComponent</code> config param is the render method. | ||
| This is the place where you link the Stardust bits with your custom component. This method is |
There was a problem hiding this comment.
nit-nit:
... where you might link Stardust bits with your custom component - e.g. by simply passing them as props. This
rendermethod will be invoked with the following parameters:
docs/src/views/CustomComponents.tsx
Outdated
| </p> | ||
| <ul> | ||
| <li> | ||
| <code>stardust</code> - this is the object containing the evaluated theming props (classes |
There was a problem hiding this comment.
nit: 'this is' is not necessary, can be safely omitted.
classes and rtl should be wrapped in <code />
docs/src/views/CustomComponents.tsx
Outdated
| </p> | ||
| <ul> | ||
| <li> | ||
| <code>stardust</code> - this is the object containing the evaluated theming props (classes |
There was a problem hiding this comment.
lets end each item's text with dot
docs/src/views/CustomComponents.tsx
Outdated
| </li> | ||
| </ul> | ||
| <p> | ||
| The previous implementation of the render method inside the <code>createComponent</code>{' '} |
There was a problem hiding this comment.
sorry, not sure that can completely understand what this paragraph is about - why previous and, also, it seems that there are too many commas there
There was a problem hiding this comment.
This paragraph is not really necessary as we already covered all important bits in the paragraph before the list items :)
docs/src/views/CustomComponents.tsx
Outdated
|
|
||
| <p> | ||
| We already saw how the <code>Provider</code> can define some stylings and variables for the | ||
| custom components. Next, we will take a look into few examples of how the user can further |
There was a problem hiding this comment.
'few' -> 'several/couple' (as 'few' has rather 'not enough' semantics :)
docs/src/views/CustomComponents.tsx
Outdated
| <p> | ||
| We already saw how the <code>Provider</code> can define some stylings and variables for the | ||
| custom components. Next, we will take a look into few examples of how the user can further | ||
| customize the styling and variables of the custom components, the same way they would do with |
There was a problem hiding this comment.
nit: maybe simplified:
customize the styling and variables -> customize styles and variables of these components
docs/src/views/CustomComponents.tsx
Outdated
| the Stardust components. | ||
| </p> | ||
|
|
||
| <Header as="h3" content="Example 1. Using the variables property" /> |
There was a problem hiding this comment.
would omit the and use <code>:
<Header as="h3" content={<>Example 1. Using <code>variables</code> property</>} />There was a problem hiding this comment.
also, would rather expect to see section devoted to styles prop first, as this is a first thing customer would learn about Stardust - with variables being rather more advanced concept
docs/src/views/CustomComponents.tsx
Outdated
| render={() => ( | ||
| <Provider | ||
| theme={{ | ||
| componentStyles: { |
There was a problem hiding this comment.
same here - would suggest to swap places of componentVariables and componentStyles sections
docs/src/views/CustomComponents.tsx
Outdated
| )} | ||
| /> | ||
|
|
||
| <Header as="h3" content="Example 2. Using the styles property" /> |
There was a problem hiding this comment.
just 'using styles property' should be enough
docs/src/views/CustomComponents.tsx
Outdated
|
|
||
| <ExampleSnippet | ||
| value={[ | ||
| `<StyledButton styles={({theme: {siteVariables}}) => ({backgroundColor: siteVariables.black})}>`, |
There was a problem hiding this comment.
I would rather strive for simplifying examples as much as possible. We should just show that it is possible to use styles prop, as well as suggest the fact that it could be used the same way as for Stardust components. Then I see us providing simple example that might prove that, and after this example make a sentence that all other advanced scenarios are supported as well, please, take a look on the corresponding docs.
This will allow us
- to simplify example's code (crucially important thing)
- not introduce additional maintainability burden to us - say, in case if implementation of
stylesprop change, we won't need to fix this example's code
docs/src/views/CustomComponents.tsx
Outdated
|
|
||
| <ExampleSnippet | ||
| value={[ | ||
| `<StyledButton variables={(siteVars) => ({color: siteVars.black})}>`, |
There was a problem hiding this comment.
lets try to simplify it a bit - while I do understand that this example is aimed to cover all things that are possible to do with this prop being introduced, at the same time, while being in the client's shoes, I would rather expect something pretty simple that would just deliver necessary idea to me. Otherwise, just imagine that I am not yet familiar with siteVariables and what the beast it is - should I learn that or, maybe, it is fine for me to use variables without this knowledge? I would say that the later is just fine
|
@kuzhelov thanks much for the review! All comments resolved :) |
| import * as React from 'react' | ||
| import * as cx from 'classnames' | ||
| import { NavLink } from 'react-router-dom' | ||
| import { Header } from 'semantic-ui-react' |
There was a problem hiding this comment.
I think that we can use own Header component there 😃
There was a problem hiding this comment.
Switching the theme to dark will make the Header component white, and we don't have the other themes implemented for all page (like making the background dark in dark-mode). I would not like to introduce unnecessary providers just for handling things like that. In all docs pages, the Headers are from semantic-ui, so when the dark mode will be implemented for all page, we can safely replace them all in one iteration.
| className?: string | ||
| styles?: ComponentSlotStyle | ||
| variables?: ComponentVariablesInput | ||
| children?: React.ReactNodeArray | React.ReactNode |
There was a problem hiding this comment.
We have own type for this, ReactChildren
| children?: React.ReactNodeArray | React.ReactNode | ||
| } | ||
|
|
||
| const StyledButton: React.SFC<StyledButtonProps> = createComponent<StyledButtonProps, {}>({ |
There was a problem hiding this comment.
The state is optional.
| const StyledButton: React.SFC<StyledButtonProps> = createComponent<StyledButtonProps, {}>({ | |
| const StyledButton: React.SFC<StyledButtonProps> = createComponent<StyledButtonProps>({ |
| ` StyledButton: {`, | ||
| ` root: ({ props, variables, theme: {siteVariables} }) => ({`, | ||
| ` backgroundColor: siteVariables.brand,`, | ||
| ` color: (variables as any).color,`, |
There was a problem hiding this comment.
| ` color: (variables as any).color,`, | |
| ` color: variables.color,`, |
Can we omit any this in example's code?
| StyledButton: { | ||
| root: ({ props, variables, theme: { siteVariables } }) => ({ | ||
| backgroundColor: siteVariables.brand, | ||
| color: (variables as any).color, |
There was a problem hiding this comment.
We cannot omit it here, but it is removed from the string displayed as a code in the docs page.
| /> | ||
|
|
||
| <p> | ||
| Let's go step by step throughout all bits from the <code>createComponent</code> method. |
There was a problem hiding this comment.
nit: '.. from the createComponent ..' => '... of the createComponent ...'
| and <code>rtl</code>). | ||
| </li> | ||
| <li> | ||
| <code>...props</code> - all other props provided by the user. |
There was a problem hiding this comment.
nit: maybe user props would be enough
|
|
||
| <ExampleSnippet | ||
| value={[ | ||
| `<StyledButton variables={{color: "black" }}>`, |
There was a problem hiding this comment.
just to be sure - could you, please, suggest where is the code that suggests to the user where this variable is used (i.e. styles code)?
There was a problem hiding this comment.
Added paragraph with Provider and example componentStyles that would be applied.
| /> | ||
|
|
||
| <p> | ||
| All other advanced scenarios for applying styles and variables are supported as well. For more |
There was a problem hiding this comment.
Would suggest to write it this way:
-
for each example (Styles and Variables) introduce the concluding paragraph that would tell the following (essentially, the though expressed in this paragraph: 'Note that all other scenarios for applying styles/variables are supported as well - please, take a look on the corresponding ... section for more details.')
-
introduce additional example where theming support will be mentioned (primitive example is necessary):
const customTheme = {
// component's displayName arg is used as a selector
StyledButton: {
...
}
}
<Provider theme={customTheme}>
<StyledButton>
</Provider>- and, the same way, conclude with a similar paragraph saying 'for more advanced theming scenarios, please, take a look on the corresponding Theming section'
This PR adds guide for how the custom components can be created using the renderComponent functionality in Stardust.
To do