Skip to content

Commit dc0fe95

Browse files
authored
fix: typo initalCollapsedDepth > initialCollapsedDepth (#85)
1 parent 48b7c9b commit dc0fe95

File tree

9 files changed

+70
-15
lines changed

9 files changed

+70
-15
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
## 2.0.4
2+
3+
_Oct 22, 2024_
4+
5+
- fix: typo initalCollapsedDepth > initialCollapsedDepth
6+
- chore: improved jsdoc for the props
7+
18
## 2.0.3
9+
210
_Oct 20, 2024_
311

412
- fix: xml validation

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ When the xml is invalid, invalidXml component will be returned.\
6060
Allow collapse/expand tags by click on them. When tag is collapsed its content and attributes are hidden.\
6161
**Default**: false
6262

63-
### initalCollapsedDepth (number)
63+
### initialCollapsedDepth (number)
6464
When the **collapsible** is true, this set the level that will be started as collapsed. For example, if you want to everything starts as collapsed, set 0.\
6565
**Default**: undefined
6666

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-xml-viewer",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "Simple xml viewer component for React",
55
"author": "alissonmbr",
66
"license": "MIT",

src/components/XMLViewer.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ export default function XMLViewer(props: XMLViewerProps): JSX.Element {
1515
indentSize = 2,
1616
invalidXml,
1717
initalCollapsedDepth,
18+
initialCollapsedDepth,
1819
} = props;
1920
const [theme, setTheme] = useState<Theme>(() => ({ ...defaultTheme, ...customTheme }));
2021
const { json, valid } = useXMLViewer(xml);
2122
const context = useMemo(
22-
() => ({ theme, collapsible, indentSize, initalCollapsedDepth }),
23-
[theme, collapsible, indentSize, initalCollapsedDepth],
23+
() => ({
24+
theme,
25+
collapsible,
26+
indentSize,
27+
initialCollapsedDepth: initialCollapsedDepth ?? initalCollapsedDepth,
28+
}),
29+
[theme, collapsible, indentSize, initalCollapsedDepth, initialCollapsedDepth],
2430
);
2531

2632
useEffect(() => {

src/components/__tests__/XMLViewer.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('XMLViewer', () => {
145145
</level1>
146146
</root>
147147
`
148-
render(<XMLViewer xml={xml} collapsible initalCollapsedDepth={1} />);
148+
render(<XMLViewer xml={xml} collapsible initialCollapsedDepth={1} />);
149149
expect(screen.getAllByText('root')).toHaveLength(2);
150150
expect(screen.getAllByText('level1')).toHaveLength(2);
151151
expect(screen.queryByText('this should be collapsed')).toBeNull();

src/components/types.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,104 @@
11
export interface Theme {
22
/**
3+
* The tag name color (`<tag-name />`)
34
*
5+
* @default #d43900
46
*/
57
tagColor?: string;
68
/**
9+
* The text color (`<tag>Text</tag>`)
710
*
11+
* @default #333
812
*/
913
textColor?: string;
1014
/**
15+
* The attribute key color (`<tag attribute-key="hello" />`)
1116
*
17+
* @default #2a7ab0
1218
*/
1319
attributeKeyColor?: string;
1420
/**
21+
* The attribute value color (` <tag attr="Attribute value">`)
1522
*
23+
* @default #008000
1624
*/
1725
attributeValueColor?: string;
1826
/**
27+
* The separators colors (`<, >, </, />, =, <?, ?>`)
1928
*
29+
* @default #333
2030
*/
2131
separatorColor?: string;
2232
/**
33+
* The comment color (`<!-- this is a comment -->`)
2334
*
35+
* @default #aaa
2436
*/
2537
commentColor?: string;
2638
/**
39+
* the cdata element color (`<![CDATA[some stuff]]>`)
2740
*
41+
* @default #1D781D
2842
*/
2943
cdataColor?: string;
3044
/**
45+
* The font family
46+
*
3147
* @default monospace
3248
*/
3349
fontFamily?: string;
3450
}
3551

3652
export interface XMLViewerProps {
3753
/**
38-
* A xml in string format
54+
* A xml string to prettify.
3955
*/
4056
xml: string;
4157
/**
58+
* An object to customize the default theme.
4259
*
60+
* @default
61+
* ```js
62+
* {
63+
* tagColor: '#d43900',
64+
* textColor: '#333',
65+
* attributeKeyColor: '#2a7ab0',
66+
* attributeValueColor: '#008000',
67+
* separatorColor: '#333',
68+
* commentColor: '#aaa',
69+
* cdataColor: '#1d781d',
70+
* fontFamily: 'monospace',
71+
* }
72+
* ```
4373
*/
4474
theme?: Theme;
4575
/**
46-
*
76+
* The size of the indentation.
77+
*
4778
* @default 2
4879
*/
4980
indentSize?: number;
5081
/**
82+
* When the xml is invalid, invalidXml component will be returned.
5183
*
84+
* @default <div>Invalid XML!</div>
5285
*/
5386
invalidXml?: JSX.Element;
5487
/**
88+
* Allow collapse/expand tags by click on them. When tag is collapsed its content and attributes are hidden.
89+
*
5590
* @default false
5691
*/
5792
collapsible?: boolean;
5893
/**
59-
*
94+
* @deprecated use the initialCollapsedDepth instead
6095
*/
6196
initalCollapsedDepth?: number;
97+
/**
98+
* When the **collapsible** is true, this set the level that will be started as collapsed.
99+
* For example, if you want to everything starts as collapsed, set 0.
100+
*
101+
* @default undefined
102+
*/
103+
initialCollapsedDepth?: number;
62104
}

src/hooks/useCollapsible.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import _isNil from 'lodash/isNil';
33
import { useEffect, useState } from 'react';
44

55
export function useCollapsible(level: number) {
6-
const { collapsible, initalCollapsedDepth } = useXMLViewerContext();
6+
const { collapsible, initialCollapsedDepth } = useXMLViewerContext();
77
const [collapsed, setCollapsed] = useState(() =>
8-
_isNil(initalCollapsedDepth) || !collapsible ? false : level >= initalCollapsedDepth,
8+
_isNil(initialCollapsedDepth) || !collapsible ? false : level >= initialCollapsedDepth,
99
);
1010
const toggleCollapsed = () => setCollapsed((currentCollapsed) => !currentCollapsed);
1111

1212
useEffect(() => {
1313
setCollapsed(
14-
_isNil(initalCollapsedDepth) || !collapsible ? false : level >= initalCollapsedDepth,
14+
_isNil(initialCollapsedDepth) || !collapsible ? false : level >= initialCollapsedDepth,
1515
);
16-
}, [initalCollapsedDepth, level, collapsible]);
16+
}, [initialCollapsedDepth, level, collapsible]);
1717

1818
return {
1919
collapsed,

src/stories/XMLViewer.stories.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ const meta = {
6969
argTypes: {
7070
invalidXml: {
7171
table: {
72-
7372
disable: true,
7473
},
7574
},
@@ -85,6 +84,6 @@ export const Primary: Story = {
8584
indentSize: 2,
8685
collapsible: true,
8786
theme: defaultTheme,
88-
initalCollapsedDepth: undefined
87+
initialCollapsedDepth: undefined,
8988
},
9089
};

src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ export interface IXmlViewerContext {
1717
collapsible: boolean;
1818
indentSize: number;
1919
theme: Theme;
20-
initalCollapsedDepth?: number;
20+
initialCollapsedDepth?: number;
2121
}

0 commit comments

Comments
 (0)