mirror of
https://github.com/hanzoai/gui.git
synced 2026-10-25 02:31:41 +00:00
Both old names are owned by a different npm account (artemis-prime), so publishing them returns 403 — which is how this surfaced: the 8.0.0 run shipped @hanzogui/logo and @hanzogui/demos depending on [email protected], a version that cannot be published and therefore does not exist. Those two were uninstallable. @hanzo/gui and @hanzogui/* are ours, so the framework now carries the name it is imported by everywhere downstream, and the loader moves under the scope we control. The rewrite is limited to package references. `DEBUG?.startsWith('hanzogui')` is a log-namespace filter and join(dir, 'hanzogui') is a path — rewriting either would change behaviour, so both are untouched. Co-authored-by: Hanzo Dev <[email protected]>
116 lines
2.8 KiB
Plaintext
116 lines
2.8 KiB
Plaintext
---
|
|
title: Text
|
|
description: Text primitives with themes custom to each font.
|
|
name: text
|
|
component: Paragraph
|
|
package: text
|
|
demoName: Text
|
|
---
|
|
|
|
<HeroContainer demoMultiple>
|
|
<TextDemo />
|
|
</HeroContainer>
|
|
|
|
```tsx hero template=Text
|
|
|
|
```
|
|
|
|
<Highlights
|
|
features={[
|
|
'Themes that give you control over spacing, weights, and sizes custom to each font.',
|
|
'Size prop that automatically matches all theme values.',
|
|
'Media query styles, hoverStyle, pressStyle, focusStyle.',
|
|
]}
|
|
/>
|
|
|
|
## Installation
|
|
|
|
Text is already installed in `hanzogui`, or you can install it independently:
|
|
|
|
```bash
|
|
npm install @hanzogui/text
|
|
```
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
export default () => (
|
|
<>
|
|
<Text>Text</Text>
|
|
<SizableText>Sizable Text</SizableText>
|
|
<Paragraph>Paragraph</Paragraph>
|
|
</>
|
|
)
|
|
```
|
|
|
|
## Text
|
|
|
|
Text in Gui matches to Text in react-native-web, just with the added [Gui Props](/docs/intro/props).
|
|
|
|
It explicitly doesn't inherit your theme color or other font properties, as it's meant to be plain and used for extension. Below, we'll show `SizableText` which extends Text, and `Paragraph` which extends SizableText. Generally, Paragraph is the useful view as it will use theme values, while you can extend Text if you'd like to derive your own design system.
|
|
|
|
```tsx
|
|
import { Text, XStack, YStack } from '@hanzo/gui'
|
|
|
|
export default () => (
|
|
<>
|
|
<Text
|
|
// can add theme values
|
|
color="$white"
|
|
fontFamily="$body"
|
|
// or just use direct values
|
|
fontSize={20}
|
|
hoverStyle={{
|
|
color: '$colorHover',
|
|
}}
|
|
>
|
|
Lorem ipsum
|
|
</Text>
|
|
</>
|
|
)
|
|
```
|
|
|
|
## SizableText
|
|
|
|
Gui lets you define font sizing, spacing, line height, letter spacing and other properties with `createFont`, of which you can have many different configurations. We've found a nice pattern is to "align" all your keys across these sub-objects.
|
|
|
|
SizableText adds a `size` property thats defined using a [spread variant](/docs/core/styled#spread-variants) which looks for a matching key on each of these properties (using `@hanzogui/get-font-sized`):
|
|
|
|
- color
|
|
- fontStyle
|
|
- textTransform
|
|
- fontFamily
|
|
- fontWeight
|
|
- letterSpacing
|
|
- fontSize
|
|
- lineHeight
|
|
|
|
So, if you've defined `small`, `medium` and `large` keys on each createFont category, you can use it like so:
|
|
|
|
```tsx
|
|
<SizableText size="$small" />
|
|
```
|
|
|
|
[Source code for SizableText](https://github.com/hanzoai/gui/blob/main/pkgs/ui/text/src/SizableText.tsx).
|
|
|
|
## Paragraph
|
|
|
|
Paragraph extends SizableText and is defined as:
|
|
|
|
```tsx
|
|
export const Paragraph = styled(SizableText, {
|
|
name: 'Paragraph',
|
|
tag: 'p',
|
|
userSelect: 'auto',
|
|
color: '$color',
|
|
size: '$true',
|
|
whiteSpace: 'normal',
|
|
})
|
|
```
|
|
|
|
<Notice>
|
|
Note: Paragraph renders to a `p` tag on web, which can cause issues when you nest them
|
|
during SSR. If you don't mind rendering to a span, use `SizableText`, otherwise, be
|
|
careful when nesting items inside a Paragraph.
|
|
</Notice>
|