Skip to content
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

feat: use sx hook #397

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/3.4.x/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@
{
"id": "use-accessible-colors",
"title": "useAccessibleColors"
},
{
"id": "use-sx",
"title": "useSx"
}
]
},
Expand Down
84 changes: 84 additions & 0 deletions docs/3.4.x/use-sx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
id: use-sx
title: useSx
---

`useTheme` is custom hook which provides headless NativeBase to resolve your style props.

## Import

```jsx
import { useSx } from "native-base";
```

- It can be used to create custom component with NativeBase theme engine.
- It support resopnsive styling.

<br/>
:::note

useSx doesn't support `resopnsive` style with `SSR`.
:::

## Example

```jsx
import { useSx } from "native-base";

export const Example = () => {
const sx = useSx();
return (
<View
style={[
sx({
p: 2,
bg: ["blue.300", "violet.400", "red.400"],
width: 48,
height: 48,
}),
]}
>
<Text style={sx({ color: ["orange.900", "white", "black"] })}>
New Feat useSx in NativeBase
</Text>
</View>
);
};
```

## Example with TypeScript

```jsx
import { useSx } from "native-base";
import type { StyledProps } from "native-base";

const textStyle: StyledProps = {
color: ["orange.900", "white", "black"],
textAlign: "center",
};
const containerStyle: StyledProps = {
p: 2,
bg: ["blue.300", "violet.400", "red.400"],
width: 48,
height: 48,
};

export const Example = () => {
const sx = useSx();
return (
<View style={sx(containerStyle)}>
<Text style={sx(textStyle)}>New Feat useSx in NativeBase</Text>
</View>
);
};
```

:::note

`Size` prop will be always converted into `width` and `height`.
:::

### What doesn't support?

- variants can't be used in useSx.
- Pseudo props, internal pseudo props.
4 changes: 4 additions & 0 deletions docs/next/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@
{
"id": "use-accessible-colors",
"title": "useAccessibleColors"
},
{
"id": "use-sx",
"title": "useSx"
}
]
},
Expand Down
84 changes: 84 additions & 0 deletions docs/next/use-sx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
id: use-sx
title: useSx
---

`useTheme` is custom hook which provides headless NativeBase to resolve your style props.

## Import

```jsx
import { useSx } from "native-base";
```

- It can be used to create custom component with NativeBase theme engine.
- It support resopnsive styling.

<br/>
:::note

useSx doesn't support `resopnsive` style with `SSR`.
:::

## Example

```jsx
import { useSx } from "native-base";

export const Example = () => {
const sx = useSx();
return (
<View
style={[
sx({
p: 2,
bg: ["blue.300", "violet.400", "red.400"],
width: 48,
height: 48,
}),
]}
>
<Text style={sx({ color: ["orange.900", "white", "black"] })}>
New Feat useSx in NativeBase
</Text>
</View>
);
};
```

## Example with TypeScript

```jsx
import { useSx } from "native-base";
import type { StyledProps } from "native-base";

const textStyle: StyledProps = {
color: ["orange.900", "white", "black"],
textAlign: "center",
};
const containerStyle: StyledProps = {
p: 2,
bg: ["blue.300", "violet.400", "red.400"],
width: 48,
height: 48,
};

export const Example = () => {
const sx = useSx();
return (
<View style={sx(containerStyle)}>
<Text style={sx(textStyle)}>New Feat useSx in NativeBase</Text>
</View>
);
};
```

:::note

`Size` prop will be always converted into `width` and `height`.
:::

### What doesn't support?

- variants can't be used in useSx.
- Pseudo props, internal pseudo props.