Skip to content

Commit

Permalink
fix(Decorator): allow decorator to inherit parent theme (#5358)
Browse files Browse the repository at this point in the history
* fix: allow decorator to inherit parent theme

* fix: cspell and mdx formatting issues
  • Loading branch information
paul-balchin-ibm committed Jun 18, 2024
1 parent 8a0d1a4 commit 904602b
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 33 deletions.
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"scrollend",
"semibold",
"serializers",
"setlabeltitle",
"setsize",
"sidepanel",
"skipnav",
Expand Down Expand Up @@ -173,6 +174,7 @@
"treegrid",
"treeview",
"typeahead",
"typeof",
"unauthorizedemptystate",
"userprofileimage",
"uuidv",
Expand Down
3 changes: 2 additions & 1 deletion packages/ibm-products/src/components/Decorator/Decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ Decorator.propTypes = {
small: PropTypes.bool,

/**
* Determines the theme of the component.
* Override the default theme of the component.
* Useful if you want "invert" the component's theme.
*/
theme: PropTypes.oneOf(['light', 'dark']),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{/* cspell:ignore setlabeltitle */}
import { Story, Controls, Source, Canvas } from '@storybook/addon-docs';
import { CodesandboxLink } from '../../global/js/utils/story-helper';
import { Decorator } from '.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ export default {
mapping: Object.values(scoreOptions),
options: Object.values(scoreOptions).map((_k, i) => i),
},
theme: {
control: {
type: 'select',
labels: ['use default', 'light', 'dark'],
},
mapping: {
0: null,
1: 'light',
2: 'dark',
},
options: [0, 1, 2],
},
truncateValue: {
control: {
type: 'select',
Expand All @@ -72,6 +84,7 @@ export default {
},
},
args: {
theme: 0,
truncateValue: 0,
},
};
Expand Down Expand Up @@ -113,7 +126,6 @@ Default.args = {
}`;
},
small: false,
theme: 'light',
value: '192.168.0.50',
valueTitle: '',
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const defaults = {
onContextMenuLabel: () => {},
onContextMenuValue: () => {},
scoreThresholds: [0, 4, 7, 10],
theme: 'light',
};

/**
Expand Down Expand Up @@ -54,7 +53,7 @@ export let DecoratorBase = React.forwardRef(
score,
scoreThresholds = defaults.scoreThresholds,
small,
theme = defaults.theme,
theme,
truncateValue,
value,
valueTitle,
Expand All @@ -69,7 +68,8 @@ export let DecoratorBase = React.forwardRef(
const _value = truncate(value, truncateValue);

// These class names apply to all types of DecoratorBase.
const classNames = cx(blockClass, className, `${blockClass}--${theme}`, {
const classNames = cx(blockClass, className, {
[`${blockClass}--${theme}`]: theme,
[`${blockClass}--sm`]: small,
[`${blockClass}--truncate-end`]: truncateValue === 'end',
[`${blockClass}--truncate-start`]: truncateValue === 'start',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{/* cspell:ignore setlabeltitle */}
import { Story, Controls, Source, Canvas } from '@storybook/addon-docs';
import {
getStoryId,
CodesandboxLink,
} from '../../global/js/utils/story-helper';
import { CodesandboxLink } from '../../global/js/utils/story-helper';
import { DecoratorBase } from '.';
import * as DecoratorBaseStories from './DecoratorBase.stories';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ export default {
mapping: Object.values(scoreOptions),
options: Object.values(scoreOptions).map((_k, i) => i),
},
theme: {
control: {
type: 'select',
labels: ['use default', 'light', 'dark'],
},
mapping: {
0: null,
1: 'light',
2: 'dark',
},
options: [0, 1, 2],
},
truncateValue: {
control: {
type: 'select',
Expand All @@ -77,6 +89,7 @@ export default {
},
},
args: {
theme: 0,
truncateValue: 0,
},
};
Expand Down Expand Up @@ -124,7 +137,6 @@ Default.args = {
}`;
},
small: false,
theme: 'light',
value: '192.168.0.50',
valueTitle: '',
};
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ DecoratorDualButton.propTypes = {
small: PropTypes.bool,

/**
* Determines the theme of the component.
* Override the default theme of the component.
* Useful if you want "invert" the component's theme.
*/
theme: PropTypes.oneOf(['light', 'dark']),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{/* cspell:ignore setlabeltitle */}
import { Story, Controls, Source, Canvas } from '@storybook/addon-docs';
import {
getStoryId,
CodesandboxLink,
} from '../../global/js/utils/story-helper';
import { CodesandboxLink } from '../../global/js/utils/story-helper';
import { DecoratorDualButton } from '.';
import * as DecoratorDualButtonStories from './DecoratorDualButton.stories';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ export default {
mapping: Object.values(scoreOptions),
options: Object.values(scoreOptions).map((_k, i) => i),
},
theme: {
control: {
type: 'select',
labels: ['use default', 'light', 'dark'],
},
mapping: {
0: null,
1: 'light',
2: 'dark',
},
options: [0, 1, 2],
},
truncateValue: {
control: {
type: 'select',
Expand All @@ -77,6 +89,7 @@ export default {
},
},
args: {
theme: 0,
truncateValue: 0,
},
};
Expand Down Expand Up @@ -126,7 +139,6 @@ Default.args = {
}`;
},
small: false,
theme: 'light',
value: '192.168.0.50',
valueTitle: '',
};
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ DecoratorLink.propTypes = {
small: PropTypes.bool,

/**
* Determines the theme of the component.
* Override the default theme of the component.
* Useful if you want "invert" the component's theme.
*/
theme: PropTypes.oneOf(['light', 'dark']),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{/* cspell:ignore setlabeltitle */}
import { Story, Controls, Source, Canvas } from '@storybook/addon-docs';
import {
getStoryId,
CodesandboxLink,
} from '../../global/js/utils/story-helper';
import { CodesandboxLink } from '../../global/js/utils/story-helper';
import { DecoratorLink } from '.';
import * as DecoratorLinkStories from './DecoratorLink.stories';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ export default {
mapping: Object.values(scoreOptions),
options: Object.values(scoreOptions).map((_k, i) => i),
},
theme: {
control: {
type: 'select',
labels: ['use default', 'light', 'dark'],
},
mapping: {
0: null,
1: 'light',
2: 'dark',
},
options: [0, 1, 2],
},
truncateValue: {
control: {
type: 'select',
Expand All @@ -77,6 +89,7 @@ export default {
},
},
args: {
theme: 0,
truncateValue: 0,
},
};
Expand Down Expand Up @@ -121,7 +134,6 @@ Default.args = {
}`;
},
small: false,
theme: 'light',
value: '192.168.0.50',
valueTitle: '',
target: '_blank',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ DecoratorSingleButton.propTypes = {
small: PropTypes.bool,

/**
* Determines the theme of the component.
* Override the default theme of the component.
* Useful if you want "invert" the component's theme.
*/
theme: PropTypes.oneOf(['light', 'dark']),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{/* cspell:ignore setlabeltitle */}
import { Story, Controls, Source, Canvas } from '@storybook/addon-docs';
import {
getStoryId,
CodesandboxLink,
} from '../../global/js/utils/story-helper';
import { CodesandboxLink } from '../../global/js/utils/story-helper';
import { DecoratorSingleButton } from '.';
import * as DecoratorSingleButtonStories from './DecoratorSingleButton.stories';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ export default {
mapping: Object.values(scoreOptions),
options: Object.values(scoreOptions).map((_k, i) => i),
},
theme: {
control: {
type: 'select',
labels: ['use default', 'light', 'dark'],
},
mapping: {
0: null,
1: 'light',
2: 'dark',
},
options: [0, 1, 2],
},
truncateValue: {
control: {
type: 'select',
Expand All @@ -75,6 +87,7 @@ export default {
},
},
args: {
theme: 0,
truncateValue: 0,
},
};
Expand Down Expand Up @@ -122,7 +135,6 @@ Default.args = {
}`;
},
small: false,
theme: 'light',
value: '192.168.0.50',
valueTitle: '',
};

0 comments on commit 904602b

Please sign in to comment.