The init
command sets up TrendUI and configures it based on your preferences.
Command:
npx trendui init
When you run the command, it prompts you to answer a series of questions:
-
Would you like to use TypeScript?
- Choose whether you want the setup to include TypeScript support.
-
Would you like to use Tailwind CSS?
- Enable Tailwind CSS integration for styling components.
-
Where would you like to store your components?
- Specify the directory where TrendUI components will be stored (default:
trendui
).
- Specify the directory where TrendUI components will be stored (default:
Based on your responses:
- The CLI creates a configuration file (
trendui.config.js
) with your preferences. - If Tailwind CSS is enabled, the CLI automatically:
- Installs Tailwind CSS, Nativewind, and twrnc.
- Sets up a
tailwind.config.js
file tailored to your project. - Configures Babel to work with Nativewind.
Use the add
command to add TrendUI components to your project.
Command:
npx trendui add [component-names]
Example:
npx trendui add button textinput
This adds the Button
and TextInput
components to your project.
The list
command displays all components available in TrendUI.
Command:
npx trendui list
-
Run the CLI to initialize TrendUI:
npx trendui init
Respond to the prompts based on your project requirements. For instance:
- Enable TypeScript.
- Use Tailwind CSS.
- Set the components directory to
src/components
.
-
Add a
Button
component:npx trendui add button
-
Verify the setup by importing and using the
Button
component in your project:import { Button } from '@trendui/react-native'; export default function App() { return <Button title="Click Me" onPress={() => alert('Hello, TrendUI!')} />; }
-
Start your development server:
npm start
The trendui.config.js
file stores your project’s TrendUI configuration. Example:
module.exports = {
typescript: true,
componentPath: "src/components",
tailwindcss: true,
};
If Tailwind CSS is enabled during initialization, the CLI will:
-
Create a
tailwind.config.js
file with the following content:module.exports = { content: [ "./app/**/*.{js,jsx,ts,tsx}", "./components/**/*.{js,jsx,ts,tsx}", "./trendui/**/*.{js,jsx,ts,tsx}", ], theme: { extend: {}, }, plugins: [], };
-
Update or create a Babel configuration file to integrate Nativewind:
module.exports = function (api) { api.cache(true); return { presets: [ ["babel-preset-expo", { jsxImportSource: "nativewind" }], "nativewind/babel", ], }; };
With the TrendUI CLI, setting up and managing your components is quick and easy. Explore the power of automation and focus on building exceptional user experiences!