Skip to content

Commit c046a5f

Browse files
authored
Merge pull request storybookjs#33923 from storybookjs/sidnioulz/object-code-debt
Controls: Fix Object contrast issue and tidy up code
2 parents 9334c23 + 967875e commit c046a5f

4 files changed

Lines changed: 32 additions & 120 deletions

File tree

code/addons/docs/src/blocks/controls/Object.tsx

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
import type { ComponentProps, FC, FocusEvent, SyntheticEvent } from 'react';
1+
import type { FC, FocusEvent, SyntheticEvent } from 'react';
22
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
33

44
import { Button, Form, ToggleButton } from 'storybook/internal/components';
55

66
import { AddIcon, SubtractIcon } from '@storybook/icons';
77

88
import { cloneDeep } from 'es-toolkit/object';
9-
import { type Theme, styled, useTheme } from 'storybook/theming';
9+
import { styled, useTheme } from 'storybook/theming';
1010

1111
import { getControlId, getControlSetterButtonId } from './helpers';
1212
import { JsonTree } from './react-editable-json-tree';
1313
import type { ControlProps, ObjectConfig, ObjectValue } from './types';
1414

1515
const { window: globalWindow } = globalThis;
1616

17-
type JsonTreeProps = ComponentProps<typeof JsonTree>;
18-
1917
const Wrapper = styled.div(({ theme }) => ({
2018
position: 'relative',
2119
display: 'flex',
@@ -39,8 +37,14 @@ const Wrapper = styled.div(({ theme }) => ({
3937
alignItems: 'center',
4038
},
4139
'.rejt-name': {
40+
color: theme.color.secondary,
4241
lineHeight: '22px',
4342
},
43+
'.rejt-not-collapsed-list': {
44+
listStyle: 'none',
45+
margin: '0 0 0 1rem',
46+
padding: 0,
47+
},
4448
'.rejt-not-collapsed-delimiter': {
4549
lineHeight: '22px',
4650
},
@@ -57,6 +61,9 @@ const Wrapper = styled.div(({ theme }) => ({
5761
background: theme.base === 'light' ? theme.color.lighter : 'hsl(0 0 100 / 0.02)',
5862
borderColor: theme.appBorderColor,
5963
},
64+
'.rejt-collapsed-value': {
65+
color: theme.color.defaultText,
66+
},
6067
}));
6168

6269
const ButtonInline = styled.button<{ primary?: boolean }>(({ theme, primary }) => ({
@@ -155,23 +162,6 @@ const selectValue = (event: SyntheticEvent<HTMLInputElement>) => {
155162

156163
export type ObjectProps = ControlProps<ObjectValue> & ObjectConfig;
157164

158-
const getCustomStyleFunction: (theme: Theme) => JsonTreeProps['getStyle'] = (theme) => () => ({
159-
name: {
160-
color: theme.color.secondary,
161-
},
162-
collapsed: {
163-
color: theme.color.dark,
164-
},
165-
ul: {
166-
listStyle: 'none',
167-
margin: '0 0 0 1rem',
168-
padding: 0,
169-
},
170-
li: {
171-
outline: 0,
172-
},
173-
});
174-
175165
export const ObjectControl: FC<ObjectProps> = ({ name, value, onChange, argType }) => {
176166
const theme = useTheme();
177167
const data = useMemo(() => value && cloneDeep(value), [value]);
@@ -266,7 +256,6 @@ export const ObjectControl: FC<ObjectProps> = ({ name, value, onChange, argType
266256
data={data}
267257
rootName={name}
268258
onFullyUpdate={onChange}
269-
getStyle={getCustomStyleFunction(theme)}
270259
cancelButtonElement={<ButtonInline type="button">Cancel</ButtonInline>}
271260
addButtonElement={
272261
<ButtonInline type="submit" primary>

code/addons/docs/src/blocks/controls/react-editable-json-tree/JsonNodeAccordion.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function JsonNodeAccordion({
9999
{name} :
100100
</Trigger>
101101
<Region
102-
role="region"
102+
role="group"
103103
id={ids.region}
104104
aria-labelledby={ids.trigger}
105105
className="rejt-accordion-region"

0 commit comments

Comments
 (0)