Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add (optional) tooltips to icons
  • Loading branch information
CarlosNZ committed Jul 10, 2025
commit a73a7ae511de6c469c7b1853d97a9f0bf908f806
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ This is a reference list of *all* possible props, divided into related sections.
| ----------------------- | ----------------------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `theme` | `ThemeInput` | `defaultTheme` | Either one of the built-in themes (imported separately), or an object specifying some or all theme properties — see [Themes](#themes--styles). |
| `icons` | `{[iconName]: JSX.Element, ... }` | `{ }` | Replace the built-in icons by specifying them here — see [Themes](#themes--styles). | |
| `showIconTooltips` | `boolean` | false | Display icon tooltips when hovering. | |
| `indent` | `number` | `3` | Specify the amount of indentation for each level of nesting in the displayed data. |
| `collapse` | `boolean\|number\|FilterFunction` | `false` | Defines which nodes of the JSON tree will be displayed "opened" in the UI on load — see [Collapse](#collapse). |
| `collapseAnimationTime` | `number` | `300` | Time (in milliseconds) for the transition animation when collapsing collection nodes. |
Expand Down Expand Up @@ -914,6 +915,11 @@ Localise your implementation (or just customise the default messages) by passing
DEFAULT_NEW_KEY: 'key',
SHOW_LESS: '(Show less)',
EMPTY_STRING: '<empty string>' // Displayed when property key is ""
// Tooltips only appear if `showIconTooltips` prop is enabled
TOOLTIP_COPY: 'Copy to clipboard',
TOOLTIP_EDIT: 'Edit',
TOOLTIP_DELETE: 'Delete',
TOOLTIP_ADD: 'Add',
}
```

Expand Down
1 change: 1 addition & 0 deletions demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ function App() {
// translations={{
// EMPTY_STRING: 'Nah',
// }}
showIconTooltips
/>
</Suspense>
</Box>
Expand Down
19 changes: 16 additions & 3 deletions src/ButtonPanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface EditButtonProps {
// eslint-disable-next-line
replacer?: (this: any, key: string, value: unknown) => string
) => string
showIconTooltips: boolean
}

export const EditButtons: React.FC<EditButtonProps> = ({
Expand All @@ -52,6 +53,7 @@ export const EditButtons: React.FC<EditButtonProps> = ({
editConfirmRef,
getNewKeyOptions,
jsonStringify,
showIconTooltips,
}) => {
const { getStyles } = useTheme()
const NEW_KEY_PROMPT = translate('KEY_NEW', nodeData)
Expand Down Expand Up @@ -160,17 +162,27 @@ export const EditButtons: React.FC<EditButtonProps> = ({
onClick={(e) => e.stopPropagation()}
>
{enableClipboard && (
<div onClick={handleCopy} className="jer-copy-pulse">
<div
onClick={handleCopy}
className="jer-copy-pulse"
title={showIconTooltips ? translate('TOOLTIP_COPY', nodeData) : undefined}
>
<Icon name="copy" nodeData={nodeData} />
</div>
)}
{startEdit && (
<div onClick={startEdit}>
<div
onClick={startEdit}
title={showIconTooltips ? translate('TOOLTIP_EDIT', nodeData) : undefined}
>
<Icon name="edit" nodeData={nodeData} />
</div>
)}
{handleDelete && (
<div onClick={handleDelete}>
<div
onClick={handleDelete}
title={showIconTooltips ? translate('TOOLTIP_DELETE', nodeData) : undefined}
>
<Icon name="delete" nodeData={nodeData} />
</div>
)}
Expand All @@ -181,6 +193,7 @@ export const EditButtons: React.FC<EditButtonProps> = ({
// For arrays, we don't need to add a key
else handleAdd('')
}}
title="Add"
>
<Icon name="add" nodeData={nodeData} />
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/CollectionNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const CollectionNode: React.FC<CollectionNodeProps> = (props) => {
collapseAnimationTime,
onMove,
enableClipboard,
showIconTooltips,
searchFilter,
searchText,
indent,
Expand Down Expand Up @@ -432,6 +433,7 @@ export const CollectionNode: React.FC<CollectionNodeProps> = (props) => {
getNewKeyOptions={getNewKeyOptions}
editConfirmRef={editConfirmRef}
jsonStringify={jsonStringify}
showIconTooltips={showIconTooltips}
/>
)

Expand Down
2 changes: 2 additions & 0 deletions src/JsonEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const Editor: React.FC<JsonEditorProps> = ({
keySort = false,
showArrayIndices = true,
showStringQuotes = true,
showIconTooltips = false,
defaultValue = null,
newKeyOptions,
minWidth = 250,
Expand Down Expand Up @@ -366,6 +367,7 @@ const Editor: React.FC<JsonEditorProps> = ({
sort,
showArrayIndices,
showStringQuotes,
showIconTooltips,
indent,
defaultValue,
newKeyOptions,
Expand Down
2 changes: 2 additions & 0 deletions src/ValueNodeWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const ValueNodeWrapper: React.FC<ValueNodeProps> = (props) => {
sort,
editConfirmRef,
jsonStringify,
showIconTooltips,
} = props
const { getStyles } = useTheme()
const {
Expand Down Expand Up @@ -388,6 +389,7 @@ export const ValueNodeWrapper: React.FC<ValueNodeProps> = (props) => {
keyboardControls={keyboardControls}
editConfirmRef={editConfirmRef}
jsonStringify={jsonStringify}
showIconTooltips={showIconTooltips}
/>
)
)}
Expand Down
4 changes: 4 additions & 0 deletions src/localisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const localisedStrings = {
DEFAULT_NEW_KEY: 'key',
SHOW_LESS: '(Show less)',
EMPTY_STRING: '<empty string>',
TOOLTIP_COPY: 'Copy to clipboard',
TOOLTIP_EDIT: 'Edit',
TOOLTIP_DELETE: 'Delete',
TOOLTIP_ADD: 'Add',
}

export type LocalisedStrings = typeof localisedStrings
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface JsonEditorProps {
keySort?: boolean | CompareFunction
showArrayIndices?: boolean
showStringQuotes?: boolean
showIconTooltips?: boolean
defaultValue?: string | number | boolean | null | object | DefaultValueFunction
newKeyOptions?: string[] | NewKeyOptionsFunction
minWidth?: string | number
Expand Down Expand Up @@ -257,6 +258,7 @@ interface BaseNodeProps {
onDelete: InternalUpdateFunction
onError?: OnErrorFunction
showErrorMessages: boolean
showIconTooltips: boolean
onMove: InternalMoveFunction
enableClipboard: boolean | CopyFunction
restrictEditFilter: FilterFunction
Expand Down