Skip to content

Commit 724b626

Browse files
committed
refactor(header): enhance style function for levels
1 parent 9168366 commit 724b626

7 files changed

Lines changed: 55 additions & 53 deletions

File tree

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { StyleSheet, ScrollView, SafeAreaView } from 'react-native';
22
import data from './data.json';
3-
import EditorJsViewer from 'react-native-editorjs-viewer';
3+
import EditorJsViewer from '@fintables/react-native-editorjs-viewer';
44

55
export default function App() {
66
return (

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fintables/react-native-editorjs-viewer",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "A React Native component for rendering Editor.js content, supporting various block types with customizable styling.",
55
"source": "./src/index.tsx",
66
"main": "./lib/commonjs/index.js",

src/components/header/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export type IHeaderProps = {
88
level: 1 | 2 | 3 | 4 | 5 | 6;
99
text: string;
1010
};
11-
style?: TextProps['style'];
12-
otherStyles?: IUseParseHtmlTags['styles'];
11+
style?: (level: 1 | 2 | 3 | 4 | 5 | 6) => TextProps['style'];
12+
otherStyles?: (level: 1 | 2 | 3 | 4 | 5 | 6) => IUseParseHtmlTags['styles'];
1313
};
1414

1515
const Header = ({ data, style, otherStyles }: IHeaderProps) => {
@@ -20,8 +20,8 @@ const Header = ({ data, style, otherStyles }: IHeaderProps) => {
2020

2121
const { parseHtmlTag, defaultTagList } = useParseHtmlTags({
2222
styles: {
23-
...otherStyles,
24-
textStyle: style,
23+
...otherStyles?.(data.level),
24+
textStyle: style?.(data.level),
2525
},
2626
});
2727

@@ -35,7 +35,7 @@ const Header = ({ data, style, otherStyles }: IHeaderProps) => {
3535
accessible
3636
accessibilityRole="header"
3737
allowFontScaling={true}
38-
style={[styles.header, headingStyleByLevel, style]}
38+
style={[styles.header, headingStyleByLevel, style?.(data.level)]}
3939
>
4040
{parsedText}
4141
</Text>

src/hooks/useComponentMap.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,49 +95,49 @@ function useComponentMap(
9595
return (
9696
<Header
9797
data={block.data}
98-
style={[
98+
style={(level) => [
9999
containerStyle,
100100
defaultStyles?.textStyle,
101-
componentStyles?.header?.textStyle,
101+
componentStyles?.header?.textStyle?.(level),
102102
]}
103-
otherStyles={{
103+
otherStyles={(level) => ({
104104
boldTextStyle: [
105105
defaultStyles?.textStyle,
106-
componentStyles?.header?.textStyle,
106+
componentStyles?.header?.textStyle?.(level),
107107
defaultStyles?.boldTextStyle,
108108
componentStyles?.header?.boldTextStyle,
109109
],
110110
italicTextStyle: [
111111
defaultStyles?.textStyle,
112-
componentStyles?.header?.textStyle,
112+
componentStyles?.header?.textStyle?.(level),
113113
defaultStyles?.italicTextStyle,
114114
componentStyles?.header?.italicTextStyle,
115115
],
116116
underlineTextStyle: [
117117
defaultStyles?.textStyle,
118-
componentStyles?.header?.textStyle,
118+
componentStyles?.header?.textStyle?.(level),
119119
defaultStyles?.underlineTextStyle,
120120
componentStyles?.header?.underlineTextStyle,
121121
],
122122
codeTextStyle: [
123123
defaultStyles?.textStyle,
124-
componentStyles?.header?.textStyle,
124+
componentStyles?.header?.textStyle?.(level),
125125
defaultStyles?.codeTextStyle,
126126
componentStyles?.header?.codeTextStyle,
127127
],
128128
markTextStyle: [
129129
defaultStyles?.textStyle,
130-
componentStyles?.header?.textStyle,
130+
componentStyles?.header?.textStyle?.(level),
131131
defaultStyles?.markTextStyle,
132132
componentStyles?.header?.markTextStyle,
133133
],
134134
linkTextStyle: [
135135
defaultStyles?.textStyle,
136-
componentStyles?.header?.textStyle,
136+
componentStyles?.header?.textStyle?.(level),
137137
defaultStyles?.linkTextStyle,
138138
componentStyles?.header?.linkTextStyle,
139139
],
140-
}}
140+
})}
141141
/>
142142
);
143143
},

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ export type EditorJsViewerProps = {
7070
defaultStyles?: IUseParseHtmlTags['styles'];
7171
componentStyles?: {
7272
paragraph?: IUseParseHtmlTags['styles'];
73-
header?: IUseParseHtmlTags['styles'];
73+
header?: {
74+
textStyle?: (level: 1 | 2 | 3 | 4 | 5 | 6) => TextProps['style'];
75+
} & Omit<NonNullable<IUseParseHtmlTags['styles']>, 'textStyle'>;
7476
delimiter?: {
7577
containerStyle?: ViewProps['style'];
7678
textStyle?: TextProps['style'];

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"rootDir": ".",
44
"paths": {
5-
"react-native-editorjs-viewer": ["./src/index"]
5+
"@fintables/react-native-editorjs-viewer": ["./src/index"]
66
},
77
"allowUnreachableCode": false,
88
"allowUnusedLabels": false,

yarn.lock

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,40 @@ __metadata:
23742374
languageName: node
23752375
linkType: hard
23762376

2377+
"@fintables/react-native-editorjs-viewer@workspace:.":
2378+
version: 0.0.0-use.local
2379+
resolution: "@fintables/react-native-editorjs-viewer@workspace:."
2380+
dependencies:
2381+
"@commitlint/config-conventional": ^17.0.2
2382+
"@evilmartians/lefthook": ^1.5.0
2383+
"@react-native/eslint-config": ^0.73.1
2384+
"@release-it/conventional-changelog": ^5.0.0
2385+
"@types/jest": ^29.5.5
2386+
"@types/react": ^18.2.44
2387+
"@types/react-syntax-highlighter": ^15.5.13
2388+
commitlint: ^17.0.2
2389+
del-cli: ^5.1.0
2390+
eslint: ^8.51.0
2391+
eslint-config-prettier: ^9.0.0
2392+
eslint-plugin-prettier: ^5.0.1
2393+
html-entities: ^2.5.2
2394+
jest: ^29.7.0
2395+
prettier: ^3.0.3
2396+
react: 18.2.0
2397+
react-native: 0.74.5
2398+
react-native-builder-bob: ^0.30.2
2399+
react-native-code-highlighter: ^1.2.3
2400+
react-native-render-html: ^6.3.4
2401+
react-native-syntax-highlighter: ^2.1.0
2402+
react-syntax-highlighter: ^15.5.0
2403+
release-it: ^15.0.0
2404+
typescript: ^5.2.2
2405+
peerDependencies:
2406+
react: "*"
2407+
react-native: "*"
2408+
languageName: unknown
2409+
linkType: soft
2410+
23772411
"@graphql-typed-document-node/core@npm:^3.1.0":
23782412
version: 3.2.0
23792413
resolution: "@graphql-typed-document-node/core@npm:3.2.0"
@@ -13007,40 +13041,6 @@ __metadata:
1300713041
languageName: unknown
1300813042
linkType: soft
1300913043

13010-
"react-native-editorjs-viewer@workspace:.":
13011-
version: 0.0.0-use.local
13012-
resolution: "react-native-editorjs-viewer@workspace:."
13013-
dependencies:
13014-
"@commitlint/config-conventional": ^17.0.2
13015-
"@evilmartians/lefthook": ^1.5.0
13016-
"@react-native/eslint-config": ^0.73.1
13017-
"@release-it/conventional-changelog": ^5.0.0
13018-
"@types/jest": ^29.5.5
13019-
"@types/react": ^18.2.44
13020-
"@types/react-syntax-highlighter": ^15.5.13
13021-
commitlint: ^17.0.2
13022-
del-cli: ^5.1.0
13023-
eslint: ^8.51.0
13024-
eslint-config-prettier: ^9.0.0
13025-
eslint-plugin-prettier: ^5.0.1
13026-
html-entities: ^2.5.2
13027-
jest: ^29.7.0
13028-
prettier: ^3.0.3
13029-
react: 18.2.0
13030-
react-native: 0.74.5
13031-
react-native-builder-bob: ^0.30.2
13032-
react-native-code-highlighter: ^1.2.3
13033-
react-native-render-html: ^6.3.4
13034-
react-native-syntax-highlighter: ^2.1.0
13035-
react-syntax-highlighter: ^15.5.0
13036-
release-it: ^15.0.0
13037-
typescript: ^5.2.2
13038-
peerDependencies:
13039-
react: "*"
13040-
react-native: "*"
13041-
languageName: unknown
13042-
linkType: soft
13043-
1304413044
"react-native-render-html@npm:^6.3.4":
1304513045
version: 6.3.4
1304613046
resolution: "react-native-render-html@npm:6.3.4"

0 commit comments

Comments
 (0)