Customizing the main color scheme in Naive-UI with typescript

I am a beginner with Naive and I want to change the primary color of my app theme to orange. Initially, I used vuestic for this purpose but now I am struggling to implement it. Below is my main.ts file where I had the vuestic override (commented out). Can anyone guide me on how to use themeOverride? Thanks in advance!


    import { createApp } from "vue";
    import App from "./app/App.vue";
    import router from "./router";
    import { store, key } from "./store";
    import { use } from "echarts/core";
    import ECharts from "vue-echarts";

    // Importing ECharts modules manually to reduce bundle size
    import { CanvasRenderer } from "echarts/renderers";
    import { BarChart, LineChart, GaugeChart } from "echarts/charts";
    import {
      GridComponent,
      TooltipComponent,
      TitleComponent,
      MarkLineComponent,
      ToolboxComponent,
      BrushComponent,
    } from "echarts/components";
    import "vuestic-ui/dist/vuestic-ui.css";
    import naive from "naive-ui";
    import { NConfigProvider, GlobalThemeOverrides } from 'naive-ui'

    use([
      CanvasRenderer,
      BarChart,
      LineChart,
      GaugeChart,
      BrushComponent,
      MarkLineComponent,
      GridComponent,
      TooltipComponent,
      TitleComponent,
      ToolboxComponent,
    ]);

    const themeOverride: GlobalThemeOverrides = {
      common: {
        primaryColor: "ff6700"
      }
    }

    createApp(App)
      .use(store, key)
      .use(router)
      // .use(VuesticPlugin, {
      //   colors: {
      //     primary: "#ff6700",
      //   },
      // })
      .use(naive)
      .component("v-chart", ECharts)
      .mount("#AppMount");
  

Answer №1

In order to properly configure your themeOverrides, make sure to pass it as a prop to your configuration provider component. Here's an example:

<script lang="ts">
  import { NConfigProvider, GlobalThemeOverrides } from 'naive-ui'

  const themeOverrides: GlobalThemeOverrides = {
    common: {
      primaryColor: '#FF8C00'
    }
  }
</script>

<template>
  <n-config-provider :theme-overrides="themeOverrides">
    <my-app />
  </n-config-provider>
</template>

Hope this helps! :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for leveraging stage 3 functionalities in TypeScript?

Array.prototype.at() is currently in the proposal stage 3. Even after adding "lib": ["ESNext"] to my tsconfig.json, I encountered the error: Property 'at' does not exist on type 'number[]'. Could you shed some light ...

The keys within a TypeScript partial object are defined with strict typing

Currently, I am utilizing Mui components along with TypeScript for creating a helper function that can generate extended variants. import { ButtonProps, ButtonPropsSizeOverrides } from "@mui/material"; declare module "@mui/material/Button&q ...

What is the reason behind continuously receiving the error message stating "Not all code paths return a value here"?

Can someone help me understand why I am consistently encountering this error message from typescript? PS. I am aware that in this scenario I could simply use a boolean and not create a function, but my focus here is on typescript. I keep receiving the er ...

Transforming date and timezone offset into an isoDate format using moment.js

When retrieving data from the API, I encounter Date, Time, and Offset values in separate columns. My goal is to obtain an ISO date while maintaining the original date and time values. const date = "2019-04-15" const time = "13:45" const ...

Creating a cutting-edge object using Angular 4 class - The power of dynamism

Attempting to create a dynamic object within a function, but encountering recognition issues. function1(object: object) { return new object(); } The function is invoked as follows: function1(Test) 'Test' represents a basic Class implementatio ...

Attempting to showcase information on the Angular frontend

When attempting to retrieve the Street name, I am seeing [object Object]. What is the optimal approach for displaying JSON data on the client side? I managed to display a street name but struggled with other components. How can I access the other elements ...

After installing Highcharts, an error occurs stating 'Highcarts is not defined'

I am trying to incorporate Highcharts into an Angular 5 project using the ng2-highcharts npm package. However, I keep encountering an error stating that 'highcharts is not defined'. In my Angular 5 project, I have integrated Highcharts and utili ...

In TypeScript, develop a specialized Unwrap<T> utility type

After successfully creating a helper type to unwrap the inner type of an Observable<T>, I began wondering how to make this type completely generic. I wanted it to apply to any type, not just Observable, essentially creating Unwrap<T>. Here is ...

The testing for React and TypeScript did not succeed. It is recommended to utilize the "jsdom" test environment for better results

I'm working on a basic React/TypeScript project and diving into the world of testing. I've opted for React Testing Library and Jest to test a straightforward product page that should display the message "Welcome to our product page." Unfortunate ...

What is the best way to show/hide group items in a PrimeNG dropdown menu?

Is it possible to show or hide group items when clicking on the group header if the group contains items? For instance, I would like to display 3 items (AA, BB, CC) in a dropdown menu. The first 2 options (AA and BB) should be selectable, but when I click ...

Is it possible to incorporate regular React JSX with Material UI, or is it necessary to utilize TypeScript in this scenario?

I'm curious, does Material UI specifically require TypeScript or can we use React JSX code instead? I've been searching for an answer to this question without any luck, so I figured I'd ask here. ...

How to retrieve the value of an input field in Angular 2/Typescript without using ngModel

Currently, I'm utilizing Typescript in conjunction with Angular2, mirroring the structure of the Angular2 Tour of Heroes guide. There is a specific input field that I aim to associate a change event with, triggering custom logic whenever the value wi ...

Some challenges encountered in Typescript/tslint

Just starting out with Typescript and trying basic annotations. First, having trouble with one of the imports. Second, unable to recognize type inside object destructuring. Third, facing issues with JSX implementation. Here is my code: import * as React ...

Mapping Colors within a Designated Range

I am facing a slight issue where I need to draw points in different colors based on a specific value associated with each point within a certain range. The colors should transition from red to yellow to green depending on the value. Currently, I have set ...

Issue with InversifyJS @multiInject: receiving an error stating "ServiceIdentifier has an ambiguous match"

Having an issue with inversifyJs while trying to implement dependency injection in my TypeScript project. Specifically, when using the @multiInject decorator, I keep receiving the error "Ambiguous match found for serviceIdentifier". I've been referenc ...

Automatically generated error notifications for Express-Validator

I am looking to implement an Express API and incorporate request input validation using express-validator. Here is my current validation middleware: protected validate = async (request: Request, response: Response, next: NextFunction): Promise<void> ...

Iterate through each item in an object using Angular

I attempted to utilize a forEach loop, but it's indicating that it's undefined for some reason. Here is my code snippet: var array: MoneyDTO[] = prices array.forEach(function (money: MoneyDTO) { if (money.currency == 'QTW& ...

What is the process for importing WebAssembly functions into TypeScript?

I currently have a TypeScript project and am in the process of incorporating a WebAssembly Module to replace certain functionalities. Successfully importing the WebAssembly module involved moving the .wasm loading logic to its own .js file, which is then ...

transformation of categorized unions in software development

Experimenting with routing-controllers and its built-in class-transformer feature, I tried creating an interface for executing a search query based on either a location id or location coordinate. My aim was to utilize a discriminated union as a body parame ...

Establish a connection between a React variable and state management

In my codebase, I have an external module file named Task.ts. It contains the following: const taskList: Task[] = []; Class Task { ... } export { Task, taskList } The taskList is a list of Task objects that can be modified by the Task class. Now, i ...