Skip to content

Commit 597ecb1

Browse files
authored
feat: allow style overwrite (#181)
* Allow style overwrite * Add JSDoc comments * Rename devToolUI style prop to styles
1 parent afb620e commit 597ecb1

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/devTool.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createStore, StateMachineProvider } from 'little-state-machine';
22
import * as React from 'react';
33
import { Control, FieldValues, useFormContext } from 'react-hook-form';
44
import { v4 as generateUUID } from 'uuid';
5-
import { DevToolUI } from './devToolUI';
5+
import { DevToolUI, DevtoolUIProps } from './devToolUI';
66
import { useExportControlToExtension } from './extension/useExportControlToExtension';
77
import type { PLACEMENT } from './position';
88

@@ -21,11 +21,12 @@ if (typeof window !== 'undefined') {
2121
);
2222
}
2323

24-
export const DevTool = <T extends FieldValues>(props?: {
25-
id?: string;
26-
control?: Control<T>;
27-
placement?: PLACEMENT;
28-
}) => {
24+
export const DevTool = <T extends FieldValues>(
25+
props?: {
26+
id?: string;
27+
control?: Control<T>;
28+
} & Pick<DevtoolUIProps, 'placement' | 'styles'>,
29+
) => {
2930
const methods = useFormContext();
3031

3132
const uuid = React.useRef('');
@@ -47,6 +48,7 @@ export const DevTool = <T extends FieldValues>(props?: {
4748
<DevToolUI
4849
control={props?.control ?? methods.control}
4950
placement={props?.placement}
51+
styles={props?.styles}
5052
/>
5153
</StateMachineProvider>
5254
);

src/devToolUI.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ import { useStateMachine } from 'little-state-machine';
1111
import { setVisible } from './settingAction';
1212
import { PLACEMENT, getPositionByPlacement } from './position';
1313

14-
interface DevtoolUIProps {
14+
export interface DevtoolUIProps {
1515
control: Control<any>;
1616
placement?: PLACEMENT;
17+
/** Custom styles for the "show/hide panel" button and for the panel div */
18+
styles?: {
19+
/** Custom styles for the "show/hide panel" button */
20+
button?: React.HTMLAttributes<HTMLButtonElement>['style'];
21+
/** Custom styles for the panel div */
22+
panel?: React.HTMLAttributes<HTMLDivElement>['style'];
23+
};
1724
}
1825

1926
export const DevToolUI: React.FC<DevtoolUIProps> = ({
2027
control,
2128
placement = 'top-right',
29+
styles,
2230
}) => {
2331
const { state, actions } = useStateMachine({
2432
setVisible,
@@ -61,6 +69,7 @@ export const DevToolUI: React.FC<DevtoolUIProps> = ({
6169
gridTemplateRows: '40px auto',
6270
fontFamily:
6371
"-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif",
72+
...styles?.panel,
6473
}}
6574
>
6675
<Header setVisible={actions.setVisible} control={control} />
@@ -79,6 +88,7 @@ export const DevToolUI: React.FC<DevtoolUIProps> = ({
7988
padding: 3,
8089
margin: 0,
8190
background: 'none',
91+
...styles?.button,
8292
}}
8393
>
8494
<Logo actions={actions} />

0 commit comments

Comments
 (0)