Installation
Prerequisites
Before installing TX Design UI, make sure you have:
- Node.js >= 14.0.0
- React >= 16.8.0
- React DOM >= 16.8.0
Installation
Install TX Design UI using your preferred package manager:
- npm
- yarn
- pnpm
npm install --save tx-design-ui
yarn add tx-design-ui
pnpm add tx-design-ui
Peer Dependencies
TX Design UI requires the following peer dependencies:
{
"react": ">=16.8.0",
"react-dom": ">=16.8.0",
"styled-components": ">=5.0.0"
}
If you don't have these installed, install them:
- npm
- yarn
npm install react react-dom styled-components
yarn add react react-dom styled-components
Basic Usage
After installation, you can import and use components:
import React from "react";
import { TxButton, TxInput, TxCheckbox } from "tx-design-ui";
function App() {
return (
<div>
<TxButton label="Click me" onClick={() => alert("Clicked!")} />
<TxInput placeholder="Enter text" />
<TxCheckbox label="Accept terms" />
</div>
);
}
export default App;
Using with TypeScript
TX Design UI is written in JavaScript but provides type definitions. To use with TypeScript:
import React, { useState } from "react";
import { TxButton, TxInput } from "tx-design-ui";
const App: React.FC = () => {
const [value, setValue] = useState<string>("");
return (
<div>
<TxInput value={value} onChange={e => setValue(e.target.value)} placeholder="Type something" />
<TxButton label="Submit" onClick={() => console.log(value)} />
</div>
);
};
export default App;
Import Components
You can import components in two ways:
Named Imports (Recommended)
import { TxButton, TxInput, TxCheckbox } from "tx-design-ui";
Individual Imports
import TxButton from "tx-design-ui/lib/components/tx-button";
import TxInput from "tx-design-ui/lib/components/tx-input";
Using Theme Colors
TX Design UI provides a centralized color system:
import { colors, theme } from "tx-design-ui";
// Use individual colors
const primaryColor = colors.primary; // "#03030f"
const dangerColor = colors.danger; // "#e45649"
// Use theme object
const buttonBg = theme.button.primary.bg;
See the Theme Colors documentation for more information.
Next Steps
- Explore the Component Documentation
- Learn about Customization
- Check out Examples
Troubleshooting
styled-components not found
If you see an error about styled-components, make sure it's installed:
npm install styled-components
Module not found
If you get module not found errors, try:
- Clear your node_modules and package-lock.json
- Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
Version Conflicts
Make sure all peer dependencies meet the minimum version requirements.
License
MIT © Tuanxu5