openai/compose-richtext

Public

mirrored fromhttps://github.com/openai/compose-richtextAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
31698d62e15def124a841935ed0bc40c64e6db88

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

docs/richtext-ui.md

128lines · modecode

1# Richtext UI
2
3[![Android Library](https://img.shields.io/badge/Platform-Android-green.svg?style=for-the-badge)](https://developer.android.com/studio/build/dependencies)
4[![JVM Library](https://img.shields.io/badge/Platform-JVM-red.svg?style=for-the-badge)](https://kotlinlang.org/docs/mpp-intro.html)
5
6A library of Composables for formatting text using higher-level concepts than are not supported by
7compose foundation, such as "ordered lists" and "headings".
8
9Richtext UI is a base library that is non-opinionated about higher level design requirements.
10If you are already using `MaterialTheme` in your compose app, you can jump to [RichText UI Material](../richtext-ui-material/index.html)
11for a quick start. There is also Material3 flavor at [RichText UI Material3](../richtext-ui-material3/index.html)
12
13## Gradle
14
15```kotlin
16dependencies {
17 implementation("com.halilibo.compose-richtext:richtext-ui:${richtext_version}")
18}
19```
20
21## [`BasicRichText`](../api/richtext-ui/com.halilibo.richtext.ui/-basic-rich-text.html)
22
23Richtext UI does not depend on Material artifact of Compose. Design agnostic API allows anyone
24to adopt Richtext UI and its extensions like Markdown to their own design and typography systems.
25Hence, just like `foundation` and `material` modules of Compose, this library also names the
26building block with `Basic` prefix.
27
28If you are planning to adopt RichText within your design system, please go ahead and check out [`RichText Material`](../richtext-ui-material/index.html)
29for inspiration.
30
31## [`RichTextScope`](../api/richtext-ui/com.halilibo.richtext.ui/-rich-text-scope/index.html)
32
33`RichTextScope` is a context wrapper around Composables that integrate and play well within Richtext
34content.
35
36## [`RichTextThemeProvider`](../api/richtext-ui/com.halilibo.richtext.ui/-rich-text-theme-provider.html)
37
38Entry point for integrating app's own typography and theme system with BasicRichText.
39
40API for this integration is highly influenced by how compose-material theming
41is designed. RichText library assumes that almost all Theme/Design systems would
42have composition locals that provide a TextStyle downstream.
43
44Moreover, text style should not include text color by best practice. Content color
45exists to figure out text color in the current context. Light/Dark theming leverages content
46color to influence not just text but other parts of theming as well.
47
48## Example
49
50Open the `Demo.kt` file in the `sample` module to play with this. Although the mentioned demo
51uses Material integrated version of `RichText`, they share exactly the same API.
52
53```kotlin
54BasicRichText(
55 modifier = Modifier.background(color = Color.White)
56) {
57 Heading(0, "Paragraphs")
58 Text("Simple paragraph.")
59 Text("Paragraph with\nmultiple lines.")
60 Text("Paragraph with really long line that should be getting wrapped.")
61
62 Heading(0, "Lists")
63 Heading(1, "Unordered")
64 ListDemo(listType = Unordered)
65 Heading(1, "Ordered")
66 ListDemo(listType = Ordered)
67
68 Heading(0, "Horizontal Line")
69 Text("Above line")
70 HorizontalRule()
71 Text("Below line")
72
73 Heading(0, "Code Block")
74 CodeBlock(
75 """
76 {
77 "Hello": "world!"
78 }
79 """.trimIndent()
80 )
81
82 Heading(0, "Block Quote")
83 BlockQuote {
84 Text("These paragraphs are quoted.")
85 Text("More text.")
86 BlockQuote {
87 Text("Nested block quote.")
88 }
89 }
90
91 Heading(0, "Info Panel")
92 InfoPanel(InfoPanelType.Primary, "Only text primary info panel")
93 InfoPanel(InfoPanelType.Success) {
94 Column {
95 Text("Successfully sent some data")
96 HorizontalRule()
97 BlockQuote {
98 Text("This is a quote")
99 }
100 }
101 }
102
103 Heading(0, "Table")
104 Table(headerRow = {
105 cell { Text("Column 1") }
106 cell { Text("Column 2") }
107 }) {
108 row {
109 cell { Text("Hello") }
110 cell {
111 CodeBlock("Foo bar")
112 }
113 }
114 row {
115 cell {
116 BlockQuote {
117 Text("Stuff")
118 }
119 }
120 cell { Text("Hello world this is a really long line that is going to wrap hopefully") }
121 }
122 }
123}
124```
125
126Looks like this:
127
128![demo rendering](img/richtext-demo.png)
129