Extend and customize Docusaurus layouts with React
Docusaurus is powered by React, allowing developers to extend or customize the website layout. You can create custom components or pages while maintaining the consistent global header and footer.
website·Indexed 30 days ago
https://finalx.vercel.appA UI component library and toolkit featuring headless components, a centralized tool package for network requests and middleware, and a dedicated CLI scaffolding tool. Includes components such as Form, Step, NavBar, Dialog, Modal, and Wrapper, as well as utilities like apiServer and httpHelper from @finalx/common.
@finalx/cli globally using your preferred package manager (npm, yarn, or pnpm) and then run the init command to generate the project structure.# Install the CLI globally
npm install @finalx/cli -g
# Generate project structure
finalx init <projectName>docs directory.BottomWrapper component from @finalx/components is specifically designed to wrap bottom-aligned content (like footers or action bars) to automatically identify and handle the bottom safe area of the device.import { BottomWrapper } from "@finalx/components";
function Index({ children }) {
return (
<BottomWrapper
style={{
width: "100vw",
height: "380rpx",
backgroundColor: "#FFF9EE",
borderRadius: "32rpx 32rpx 0 0",
boxSizing: "border-box"
}}
>
<View>...</View>
</BottomWrapper>
);
}global.config.ts file located at the project root and imported into the application's initialization file (e.g., main.ts, main.tsx, main.js, or main.jsx). Use the globalConfig function from @finalx/common to apply these settings.import { globalConfig } from "@finalx/common";
globalConfig({
log: true,
request: {
baseUrl: "https://api.finalx.cc",
wsUrl: "wss://api.finalx.cc",
wsCheckUser: true,
wsEventKey: {
eventKey: "event",
dataKey: "data"
}
},
middleware: {
userAuth: {
filterKey: ["nickname", { key: "avatar", rule: (val: any, key: string) => !!val[key] }]
}
},
component: {
wrapperOffset: { top: '0rpx', bottom: '120rpx' },
map: {
key: 'AAAA-BBBBB-CCCCC-DDDDD-EEEEE-FFFFF', // Tencent Map Key
center: { latitude: 20.2222, longitude: 120.111111 },
distance: 1000,
scale: { scale: 18, minScale: 16.2, maxScale: 19 },
bounds: {
northeast: { latitude: 30.1111111, longitude: 120.333333 },
southwest: { latitude: 30.222222, longitude: 120.444444 },
},
},
}
});@finalx/components package as a dependency using npm, yarn, or pnpm.npm install @finalx/components -sWrapper component from @finalx/components is used to automatically calculate and apply safe area spacing for the top and bottom of a page. It provides props to toggle these spacings and customize the background and styles.import { Wrapper } from "@finalx/components";
function Index({ children }) {
return (
<Wrapper
space={false} // Disable top safe area spacing
bottomSpace={false} // Disable bottom safe area spacing
bgColor="#f8ecd6"
style={{
position: 'relative',
paddingBottom: '280rpx',
minHeight: '100vh',
boxSizing: 'border-box',
}}
>
<View>...</View>
</Wrapper>
);
}pop property allows you to display a popup window associated with the step bar. It supports custom styling, positioning, and click events.interface Pop {
title?: string; // Popup title
style?: CSSProperties; // Popup styles
offset?: { left?: number; right?: number }; // Popup offset
children?: ReactElement; // Popup child elements
onClick?: () => any; // Click event handler
}Modal and BottomModal components to control behavior and styling:content property to apply custom CSS styles to the titles and descriptions of the step items.interface Content {
titleStyle?: CSSProperties; // Styles for the title
descStyle?: CSSProperties; // Styles for the description
}useRequest hook is a wrapper around taro-hooks used for managing request state (loading, data, error) and lifecycle. It takes two arguments: requestOptions (the request configuration) and an optional options object for behavior control.import { useRequest } from "@finalx/common";
const { data, loading, run } = useRequest(
{ url: APIS.USERS, method: "GET" },
{} // options
);