Back to Refine

Text

documentation/versioned_docs/version-3.xx.xx/api-reference/chakra-ui/components/fields/text.md

3.25.02.5 KB
Original Source
tsx
const { default: routerProvider } = RefineReactRouterV6;
const { default: simpleRest } = RefineSimpleRest;
setRefineProps({
  routerProvider,
  dataProvider: simpleRest("https://api.fake-rest.refine.dev"),
  Layout: RefineChakra.Layout,
  Sider: () => null,
});

const Wrapper = ({ children }) => {
  return (
    <RefineChakra.ChakraProvider theme={RefineChakra.refineTheme}>
      {children}
    </RefineChakra.ChakraProvider>
  );
};

This field lets you show basic text. It uses Mantine <Text> component.

:::info-tip Swizzle You can swizzle this component to customize it with the refine CLI :::

Usage

Let's see how to use it in a basic show page:

tsx
setInitialRoutes(["/posts/show/123"]);
import { Refine } from "@pankod/refine-core";
import { ShowButton } from "@pankod/refine-chakra-ui";

// visible-block-start
import { useShow } from "@pankod/refine-core";
import {
  Show,
  Heading,
  // highlight-next-line
  TextField,
} from "@pankod/refine-chakra-ui";

const PostShow: React.FC = () => {
  const { queryResult } = useShow<IPost>();
  const { data, isLoading } = queryResult;
  const record = data?.data;

  return (
    <Show isLoading={isLoading}>
      <Heading as="h5" size="sm">
        Id
      </Heading>
      // highlight-next-line
      <TextField value={record?.id} />
      <Heading as="h5" size="sm">
        Title
      </Heading>
      // highlight-next-line
      <TextField value={record?.title} />
    </Show>
  );
};

interface IPost {
  id: number;
  title: string;
}
// visible-block-end

const App = () => {
  return (
    <Refine
      notificationProvider={RefineChakra.notificationProvider()}
      resources={[
        {
          name: "posts",
          show: PostShow,
          list: () => (
            <RefineChakra.VStack alignItems="flex-start">
              <RefineChakra.Text>This page is empty.</RefineChakra.Text>
              <ShowButton colorScheme="black" recordItemId="123">
                Show Item 123
              </ShowButton>
            </RefineChakra.VStack>
          ),
        },
      ]}
    />
  );
};
render(
  <Wrapper>
    <App />
  </Wrapper>,
);

API Reference

Properties

<PropsTable module="@pankod/refine-chakra-ui/TextField" />

:::tip External Props It also accepts all props of Chakra UI Text. :::