Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

docs(Knobs): use new knobs#1224

Merged
layershifter merged 11 commits intomasterfrom
docs/use-new-knobs
Apr 25, 2019
Merged

docs(Knobs): use new knobs#1224
layershifter merged 11 commits intomasterfrom
docs/use-new-knobs

Conversation

@layershifter
Copy link
Member

@layershifter layershifter commented Apr 15, 2019

Follow up from #1082.

image

Replaces old knobs via new context-based. Also, fixes broken examples in ExternalLayout.

@codecov
Copy link

codecov bot commented Apr 15, 2019

Codecov Report

Merging #1224 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1224   +/-   ##
=======================================
  Coverage   72.14%   72.14%           
=======================================
  Files         731      731           
  Lines        5596     5596           
  Branches     1614     1614           
=======================================
  Hits         4037     4037           
  Misses       1554     1554           
  Partials        5        5

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e4822e0...138ce5a. Read the comment docs.

…cs/use-new-knobs

# Conflicts:
#	packages/docs-components/src/index.ts
#	packages/docs-components/src/knobs/KnobInspector.tsx
#	packages/docs-components/src/knobs/KnobProvider.tsx
#	packages/docs-components/src/knobs/defaultComponents.tsx
#	packages/docs-components/src/knobs/types.ts
@DustyTheBot
Copy link
Collaborator

Warnings
⚠️ There are no updates provided to CHANGELOG. Ensure there are no publicly visible changes introduced by this PR.

Generated by 🚫 dangerJS

@layershifter layershifter marked this pull request as ready for review April 16, 2019 16:11
defaultValue: parseValue(props.value),
unit: `${props.value}`.replace(`${parseValue(props.value)}`, ''),
}
}, [])
Copy link
Member Author

Choose a reason for hiding this comment

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

Was taken from KnobScalar 🦅

Copy link
Member

Choose a reason for hiding this comment

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

Cool, but looks like an unnecessary premature optimisation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, no. It computes defaultValue & unit once because defaultValue depends on props.value which will be changed during renders

Copy link
Member

@miroslavstastny miroslavstastny left a comment

Choose a reason for hiding this comment

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

defaultValue: parseValue(props.value),
unit: `${props.value}`.replace(`${parseValue(props.value)}`, ''),
}
}, [])
Copy link
Member

Choose a reason for hiding this comment

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

Cool, but looks like an unnecessary premature optimisation.

const LoaderExampleDelay = () => {
const [mounted] = useBooleanKnob({ name: 'mounted', initialValue: true })

return <div style={{ minHeight: 24 }}>{mounted && <Loader delay={500} />}</div>
Copy link
Member

Choose a reason for hiding this comment

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

why delay is not a knob?

Copy link
Member Author

@layershifter layershifter Apr 25, 2019

Choose a reason for hiding this comment

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

Add it there as knob 👍

children?: (children: React.ReactElement) => React.ReactElement
}

const KnobInspector: React.FunctionComponent<KnobInspectorProps> = props => {
Copy link
Member

Choose a reason for hiding this comment

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

We should decide whether we prefer FC or FunctionComponent and be consistent with it

Copy link
Member Author

Choose a reason for hiding this comment

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

As I remember we agreed on FunctionComponent, @kuzhelov ?

})}
</>
)
return props.children ? props.children(children) : children
Copy link
Member

Choose a reason for hiding this comment

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

children() confuses me. Can we use render prop?

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to follow React API, they use children: https://reactjs.org/docs/context.html#contextconsumer

@layershifter
Copy link
Member Author

layershifter commented Apr 25, 2019

_.omit() will be removed in next release: https://github.com/lodash/lodash/wiki/Roadmap#v500-2019
It also has performance issues

And this package doesn't have lodash in deps 😺

@layershifter
Copy link
Member Author

get rid of any

I don't want to fill default context with something, it should be filled by KnobProvider to avoid direct usages of KnobContext. I can do:

- components: {} as any,
+  components: {
+    KnobControl: () => null,
+    KnobField: () => null,
+    KnobLabel: () => null,
+
+    KnobBoolean: () => null,
+    KnobRange: () => null,
+    KnobSelect: () => null,
+    KnobString: () => null,
+  },

But will it better? 🤔

/>
)
const DropdownExampleLoading = () => {
const [loading] = useBooleanKnob({ name: 'loading', initialValue: true })
Copy link
Contributor

Choose a reason for hiding this comment

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

for this specific example, just to make it user friendly in terms of user being able to notice effect, I might suggest to introduce open knob in addition that will be triggered by default. This will make an effect of loading apparent to the client

@layershifter layershifter merged commit 7f47c35 into master Apr 25, 2019
@delete-merged-branch delete-merged-branch bot deleted the docs/use-new-knobs branch April 25, 2019 11:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants