-
Notifications
You must be signed in to change notification settings - Fork 63
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
15
commits into
@ksienkiewicz/docs-rich-text-formatting
from
@ksienkiewicz/docs-core-functionalities
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
98d3392
docs: core funtionalities section
hejsztynx 111711e
fix: grammar
hejsztynx d9fd012
feat: enriched text example styles
hejsztynx 4ba6815
docs: link enriched text api ref
hejsztynx 7360d09
Update docs/docs/core-functionalities/web-support.md
hejsztynx 7442b37
docs: web sanitization acknowledgement
hejsztynx 885744b
docs: web sanitization acknowledgement
hejsztynx dfd09c1
docs: sanitizationConfig tweak
hejsztynx efdea98
docs: mention notable props
hejsztynx d242810
fix: typos
hejsztynx 880f67c
docs: clarification
hejsztynx 021416d
docs: rename handling events section
hejsztynx bec24a5
docs: style prop mention
hejsztynx a2f591e
fix: docs link
hejsztynx 8268d06
docs: code review suggestions
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 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,67 @@ | ||
| --- | ||
| sidebar_position: 3 | ||
| --- | ||
|
|
||
| # Handling input events | ||
|
|
||
| Since the input is [uncontrolled](/fundamentals/core-concepts#the-input-is-uncontrolled), | ||
| events are how you observe it. You change content by calling ref methods; you | ||
| react to changes by listening to the callbacks below. | ||
|
|
||
| Full payload shapes of the available callbacks can be found in the `EnrichedTextInput` reference. | ||
|
|
||
| :::note | ||
|
|
||
| This page covers `EnrichedTextInput` events. The read-only | ||
| [`EnrichedText`](/core-functionalities/rendering-rich-text) component only | ||
| exposes `onLinkPress` and `onMentionPress` callbacks. | ||
|
|
||
| ::: | ||
|
|
||
| ## Content | ||
|
|
||
| - **`onChangeText`** - plain-text content changed. | ||
| - **`onChangeHtml`** - the HTML changed. | ||
|
|
||
| :::tip | ||
|
|
||
| The `onChangeHtml` callback has to parse the content into HTML on every keystroke. | ||
| This is a heavy computational operation that might slow down your app's performance. Consider using the `getHTML()` ref method instead if it meets your requirements. | ||
|
|
||
| ::: | ||
|
|
||
| ## Selection and style state | ||
|
|
||
| - **`onChangeSelection`** - the cursor moved or the selection changed. Gives you | ||
| `start`, `end`, and the selected `text`. Useful for range-based methods like | ||
| [`setLink`](/rich-text-formatting/links). | ||
| - **`onChangeState`** - the active styles at the cursor changed. This is the | ||
| event that drives a toolbar by using reported `isActive`, `isBlocking`, and | ||
| `isConflicting`, plus the current `alignment`. See the | ||
| [style state model](/fundamentals/core-concepts#the-style-state-model). | ||
|
|
||
| ## Focus | ||
|
|
||
| - **`onFocus`** / **`onBlur`** - the input gained or lost focus. | ||
|
|
||
| ## Mentions | ||
|
|
||
| - **`onStartMention`** - a mention started being edited. | ||
| - **`onChangeMention`** - the query after the indicator changed. | ||
| - **`onEndMention`** - editing a mention stopped. | ||
| - **`onMentionDetected`** - the cursor entered or left a mention. | ||
|
kacperzolkiewski marked this conversation as resolved.
|
||
|
|
||
| ## Links | ||
|
|
||
| - **`onLinkDetected`** - the cursor entered or left a link. | ||
|
kacperzolkiewski marked this conversation as resolved.
|
||
|
|
||
| ## Images | ||
|
|
||
| - **`onPasteImages`** - the user pasted one or more images; hands you each | ||
| image's data so you can upload and insert them with | ||
| [`setImage`](/rich-text-formatting/inline-images). | ||
|
|
||
| ## Keyboard and submission | ||
|
|
||
| - **`onKeyPress`** - a key was pressed. | ||
| - **`onSubmitEditing`** - the user pressed return/enter key. Fired when `submitBehavior` is set to either `submit` or `blurAndSubmit`. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,97 @@ sidebar_position: 1 | |
|
|
||
| # Styling the input | ||
|
|
||
| <!-- TODO: write content for this page --> | ||
| `EnrichedTextInput` is styled through two separate props. Together they cover | ||
| everything from the container's dimensions down to the color of a bullet point. | ||
|
|
||
| - **`style`** - the container's layout behavior and its base typography (`fontSize`, `color`, `fontFamily`, …). It accepts a subset of React Native's `TextStyle`, described by | ||
|
hejsztynx marked this conversation as resolved.
|
||
| `EnrichedInputStyle`. | ||
|
szydlovsky marked this conversation as resolved.
|
||
| - **`htmlStyle`** - the appearance of individual rich text elements: heading | ||
| sizes, blockquote borders, code colors, list markers, mention colors, and so | ||
| on. | ||
| - **`placeholderTextColor`** - the color of the placeholder text. | ||
| - **`selectionColor`** - the color of the text selection highlight. | ||
| - **`cursorColor`** - the color of the text cursor. | ||
|
hejsztynx marked this conversation as resolved.
|
||
|
|
||
| :::note | ||
|
|
||
| `cursorColor` is not supported on iOS. For more platform differences, see [Compatibility](/misc/compatibility). | ||
|
|
||
| ::: | ||
|
|
||
| ```tsx | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be interactive so users can change props in code tab and immediately observe results? |
||
| <EnrichedTextInput | ||
| style={{ | ||
| fontSize: 16, | ||
| color: '#232736', | ||
| padding: 12, | ||
| borderRadius: 12, | ||
| backgroundColor: '#eef0ff', | ||
| }} | ||
| htmlStyle={{ | ||
| h1: { fontSize: 28, bold: true }, | ||
| blockquote: { borderColor: '#57b495', borderWidth: 3 }, | ||
| code: { color: '#c026d3' }, | ||
| }} | ||
| /> | ||
| ``` | ||
|
|
||
| ## `style` | ||
|
|
||
| `style` accepts a subset of React Native's `TextStyle` - layout, appearance, | ||
| and base typography - described by `EnrichedInputStyle`. Most of these map directly | ||
| to their React Native `TextStyle` counterparts. Some are platform-limited | ||
| (e.g. `shadowColor` is iOS-only, `elevation` is Android-only) - see the | ||
| `EnrichedTextInput` reference for the full property list. | ||
|
|
||
| ## `htmlStyle` | ||
|
|
||
| `htmlStyle` maps each supported element to a small config object. Anything you | ||
| omit falls back to the built-in default. The available keys are: | ||
|
|
||
| | Key | Styles | Notable options | | ||
| | ------------ | -------------- | ----------------------------------------------------------- | | ||
| | `h1`–`h6` | Headings | `fontSize`, `bold` | | ||
| | `blockquote` | Blockquote | `borderColor`, `borderWidth`, `gapWidth`, `color` | | ||
| | `codeblock` | Code block | `color`, `backgroundColor`, `borderRadius` | | ||
| | `code` | Inline code | `color`, `backgroundColor` | | ||
| | `a` | Links | `color`, `textDecorationLine` | | ||
| | `mention` | Mentions | `color`, `backgroundColor`, `textDecorationLine` | | ||
| | `ol` | Ordered list | `markerColor`, `markerFontWeight`, `marginLeft`, `gapWidth` | | ||
| | `ul` | Unordered list | `bulletColor`, `bulletSize`, `marginLeft`, `gapWidth` | | ||
| | `ulCheckbox` | Checkbox list | `boxColor`, `boxSize`, `marginLeft`, `gapWidth` | | ||
|
|
||
| The full list of properties, defaults, and platform notes lives in the | ||
| `EnrichedTextInput` reference. | ||
|
|
||
| ### Styling mentions per indicator | ||
|
|
||
| `mention` accepts either a single config applied to every mention, or a record | ||
| keyed by [indicator](/rich-text-formatting/mentions) so each mention type gets | ||
| its own look: | ||
|
|
||
| ```tsx | ||
| htmlStyle={{ | ||
| mention: { | ||
| '@': { color: '#2563eb', backgroundColor: '#dbeafe' }, | ||
| '#': { color: '#16a34a', backgroundColor: '#dcfce7' }, | ||
| }, | ||
| }} | ||
| ``` | ||
|
|
||
| :::tip | ||
|
|
||
| You can also create a default `mention` style config, by using the `'default'` key. | ||
|
|
||
| ```tsx | ||
| htmlStyle={{ | ||
| mention: { | ||
| 'default': { color: '#2563eb', backgroundColor: '#dbeafe' }, | ||
| '#': { color: '#16a34a', backgroundColor: '#dcfce7' }, | ||
| }, | ||
| }} | ||
| ``` | ||
|
|
||
| This way you can create a style for any mention indicator to fallback if it doesn't have one fully defined. | ||
|
|
||
| ::: | ||
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.
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.