Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions code/addons/docs/src/blocks/controls/Object.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import type { ComponentProps, FC, FocusEvent, SyntheticEvent } from 'react';
import type { FC, FocusEvent, SyntheticEvent } from 'react';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';

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

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

useTheme import is now unused — dead code from removed getCustomStyleFunction.

const theme = useTheme() is declared on Line 166 but theme is never referenced anywhere in the component body after the getCustomStyleFunction removal. Both the import and the variable declaration should be removed.

🧹 Proposed fix
-import { styled, useTheme } from 'storybook/theming';
+import { styled } from 'storybook/theming';
 export const ObjectControl: FC<ObjectProps> = ({ name, value, onChange, argType }) => {
-  const theme = useTheme();
   const data = useMemo(() => value && cloneDeep(value), [value]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/addons/docs/src/blocks/controls/Object.tsx` at line 9, Remove the
now-unused useTheme import and its call: delete "useTheme" from the import
statement (styled, useTheme) and remove the "const theme = useTheme()"
declaration inside the Object component (left over after removing
getCustomStyleFunction) so no dead reference remains.


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

const { window: globalWindow } = globalThis;

type JsonTreeProps = ComponentProps<typeof JsonTree>;

const Wrapper = styled.div(({ theme }) => ({
position: 'relative',
display: 'flex',
Expand All @@ -39,8 +37,14 @@ const Wrapper = styled.div(({ theme }) => ({
alignItems: 'center',
},
'.rejt-name': {
color: theme.color.secondary,
lineHeight: '22px',
},
'.rejt-not-collapsed-list': {
listStyle: 'none',
margin: '0 0 0 1rem',
padding: 0,
},
'.rejt-not-collapsed-delimiter': {
lineHeight: '22px',
},
Expand All @@ -57,6 +61,9 @@ const Wrapper = styled.div(({ theme }) => ({
background: theme.base === 'light' ? theme.color.lighter : 'hsl(0 0 100 / 0.02)',
borderColor: theme.appBorderColor,
},
'.rejt-collapsed-value': {
color: theme.color.defaultText,
Comment thread
Sidnioulz marked this conversation as resolved.
},
}));

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

export type ObjectProps = ControlProps<ObjectValue> & ObjectConfig;

const getCustomStyleFunction: (theme: Theme) => JsonTreeProps['getStyle'] = (theme) => () => ({
name: {
color: theme.color.secondary,
},
collapsed: {
color: theme.color.dark,
},
ul: {
listStyle: 'none',
margin: '0 0 0 1rem',
padding: 0,
},
li: {
Comment thread
Sidnioulz marked this conversation as resolved.
outline: 0,
},
});

export const ObjectControl: FC<ObjectProps> = ({ name, value, onChange, argType }) => {
const theme = useTheme();
const data = useMemo(() => value && cloneDeep(value), [value]);
Expand Down Expand Up @@ -266,7 +256,6 @@ export const ObjectControl: FC<ObjectProps> = ({ name, value, onChange, argType
data={data}
rootName={name}
onFullyUpdate={onChange}
getStyle={getCustomStyleFunction(theme)}
cancelButtonElement={<ButtonInline type="button">Cancel</ButtonInline>}
addButtonElement={
<ButtonInline type="submit" primary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function JsonNodeAccordion({
{name} :
</Trigger>
<Region
role="region"
role="group"
Comment thread
Sidnioulz marked this conversation as resolved.
id={ids.region}
aria-labelledby={ids.trigger}
className="rejt-accordion-region"
Expand Down
Loading
Loading