-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Storybook] General consistency pass (#7245)
- Loading branch information
Showing
29 changed files
with
478 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { hideStorybookControls, disableStorybookControls } from './utils'; | ||
|
||
describe('hideStorybookControls', () => { | ||
it('outputs the expected `argTypes` object when passed prop name strings', () => { | ||
expect( | ||
hideStorybookControls(['isDisabled', 'isLoading', 'isInvalid']) | ||
).toEqual({ | ||
isDisabled: { table: { disable: true } }, | ||
isLoading: { table: { disable: true } }, | ||
isInvalid: { table: { disable: true } }, | ||
}); | ||
}); | ||
|
||
it('throws a typescript error if a generic is passed and the prop names do not match', () => { | ||
type TestComponentProps = { hello: boolean; world: boolean }; | ||
// No typescript error | ||
hideStorybookControls<TestComponentProps>(['hello', 'world']); | ||
// @ts-expect-error - will fail `yarn lint` if a TS error is *not* produced | ||
hideStorybookControls<TestComponentProps>(['hello', 'world', 'error']); | ||
}); | ||
}); | ||
|
||
describe('disableStorybookControls', () => { | ||
it('outputs the expected `argTypes` object when passed prop name strings', () => { | ||
expect( | ||
disableStorybookControls(['isDisabled', 'isLoading', 'isInvalid']) | ||
).toEqual({ | ||
isDisabled: { control: false }, | ||
isLoading: { control: false }, | ||
isInvalid: { control: false }, | ||
}); | ||
}); | ||
|
||
it('throws a typescript error if a generic is passed and the prop names do not match', () => { | ||
type TestComponentProps = { hello: boolean; world: boolean }; | ||
// No typescript error | ||
disableStorybookControls<TestComponentProps>(['hello', 'world']); | ||
// @ts-expect-error - will fail `yarn lint` if a TS error is *not* produced | ||
disableStorybookControls<TestComponentProps>(['hello', 'world', 'error']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/** | ||
* argTypes configurations | ||
*/ | ||
|
||
/** | ||
* Completely hide props from Storybook's controls panel. | ||
* Should be passed or spread to `argTypes` | ||
*/ | ||
export const hideStorybookControls = <Props>( | ||
propNames: Array<keyof Props> | ||
): Record<keyof Props, typeof HIDE_CONTROL> | {} => { | ||
return propNames.reduce( | ||
(obj, name) => ({ ...obj, [name]: HIDE_CONTROL }), | ||
{} | ||
); | ||
}; | ||
const HIDE_CONTROL = { table: { disable: true } }; | ||
|
||
/** | ||
* Leave props visible in Storybook's controls panel, but disable them | ||
* from being controllable (renders a `-`). | ||
* | ||
* Should be passed or spread to `argTypes` | ||
*/ | ||
export const disableStorybookControls = <Props>( | ||
propNames: Array<keyof Props> | ||
): Record<keyof Props, typeof DISABLE_CONTROL> | {} => { | ||
return propNames.reduce( | ||
(obj, name) => ({ ...obj, [name]: DISABLE_CONTROL }), | ||
{} | ||
); | ||
}; | ||
const DISABLE_CONTROL = { control: false }; | ||
|
||
/** | ||
* parameters configurations | ||
*/ | ||
|
||
/** | ||
* Will hide all props/controls. Pass to `parameters` | ||
* | ||
* TODO: Figure out some way to not show Storybook's "setup" text? | ||
*/ | ||
export const hideAllStorybookControls = { | ||
controls: { exclude: /.*/g }, | ||
}; | ||
|
||
/** | ||
* Will hide the control/addon panel entirely for a specific story. | ||
* Should be passed or spread to to `parameters`. | ||
* | ||
* Note that users can choose to re-show the panel in the UI | ||
*/ | ||
export const hidePanel = { | ||
options: { showPanel: false }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.