-
Notifications
You must be signed in to change notification settings - Fork 61
docs: core funtionalities section #715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hejsztynx
wants to merge
12
commits into
@ksienkiewicz/docs-rich-text-formatting
Choose a base branch
from
@ksienkiewicz/docs-core-functionalities
base: @ksienkiewicz/docs-rich-text-formatting
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c3b80cd
docs: core funtionalities section
hejsztynx b2f25f5
fix: grammar
hejsztynx 8a54cb1
feat: enriched text example styles
hejsztynx 01244ae
Merge branch '@ksienkiewicz/docs-rich-text-formatting' into @ksienkie…
hejsztynx b8933ae
docs: link enriched text api ref
hejsztynx b6fa9e6
Update docs/docs/core-functionalities/web-support.md
hejsztynx 5b09240
docs: web sanitization acknowledgement
hejsztynx 6560ad1
Merge branch '@ksienkiewicz/docs-rich-text-formatting' into @ksienkie…
hejsztynx 69ee230
docs: web sanitization acknowledgement
hejsztynx 03f546a
docs: sanitizationConfig tweak
hejsztynx 6eadff0
Merge branch '@ksienkiewicz/docs-rich-text-formatting' into @ksienkie…
hejsztynx c1829b9
docs: mention notable props
hejsztynx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| --- | ||
| sidebar_position: 2 | ||
| --- | ||
|
|
||
| import InteractiveExample from '@site/src/components/InteractiveExample'; | ||
| import RenderingEditor from '@site/src/examples/RenderingEditor'; | ||
| import RenderingEditorSrc from '!!raw-loader!@site/src/examples/RenderingEditor'; | ||
|
|
||
| # Rendering rich text | ||
|
|
||
| `EnrichedTextInput` is for editing. To _display_ rich text without an editor - | ||
| a chat message, a comment, an article - use its read-only counterpart, | ||
| **`EnrichedText`**. | ||
|
|
||
| Both components speak the same [HTML format](/fundamentals/html-format-and-supported-tags), | ||
| so the typical flow is: edit in `EnrichedTextInput`, persist the | ||
| `getHTML` output, and later feed that | ||
| string to `EnrichedText`. | ||
|
|
||
| ## Passing content | ||
|
|
||
| `EnrichedText` takes the HTML string as its `children`: | ||
|
|
||
| ```tsx | ||
| import { EnrichedText } from 'react-native-enriched-html'; | ||
|
|
||
| <EnrichedText>{'<p>Hello <b>world</b></p>'}</EnrichedText>; | ||
| ``` | ||
|
|
||
| ## Styling | ||
|
|
||
| Styling mirrors the input. `style` controls the container and base typography, | ||
| and `htmlStyle` controls per-element appearance. `EnrichedText` extends | ||
| `htmlStyle` with **press states** for interactive elements, since links and | ||
| mentions are pressable here: | ||
|
|
||
| ```tsx | ||
| <EnrichedText | ||
| style={{ fontSize: 16, color: '#232736' }} | ||
| htmlStyle={{ | ||
| a: { pressColor: '#1e40af' }, | ||
| mention: { pressColor: '#16a34a', pressBackgroundColor: '#dcfce7' }, | ||
| }}> | ||
| {html} | ||
| </EnrichedText> | ||
| ``` | ||
|
|
||
| The added `pressColor` / `pressBackgroundColor` fields on `a` and `mention` are | ||
| the only shape difference from the input's `htmlStyle`. See the | ||
| [`EnrichedText`](/api-reference/enriched-text) reference for the full type. | ||
|
|
||
| ## Notable props | ||
|
|
||
| - **`selectable`** - allow the user to select and copy the rendered text. | ||
|
hejsztynx marked this conversation as resolved.
|
||
| Defaults to `false`. | ||
| - **`onLinkPress` / `onMentionPress`** - fire when a link or mention is pressed. | ||
| - **`numberOfLines` / `ellipsizeMode`** - truncate long content to a fixed | ||
| number of lines with an ellipsis. | ||
| - **`useHtmlNormalizer`** - normalize external or messy HTML into the library's canonical | ||
| tag subset before rendering. Defaults to `true`. See | ||
| [Normalization](/fundamentals/core-concepts#normalization). | ||
| - **`allowFontScaling`** - whether to respect the system's accessibility font scaling settings. | ||
|
|
||
| :::note | ||
|
|
||
| On web, the default behavior of the pressed `<a>` tag is suppressed. To navigate to the link's URL, you need to properly handle the `onLinkPress` event. | ||
|
|
||
| ::: | ||
|
|
||
| ## Try it out | ||
|
|
||
| Format some text in the editor, then press **Render** - the current HTML is read | ||
| with `getHTML()` and handed to an `EnrichedText` below. | ||
|
|
||
| <InteractiveExample src={RenderingEditorSrc} component={RenderingEditor} /> | ||
|
|
||
| :::caution | ||
|
|
||
| On iOS and Android, `EnrichedText` does not sanitize HTML for you. Sanitize anything you render that | ||
| came from users or other untrusted sources. To know more about the web's built-in sanitization, visit [Web support](/core-functionalities/web-support#sanitization). | ||
|
|
||
| ::: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.