1.0.87 • Published 7 months ago

mdc-ui v1.0.87

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

MDC-UI: MDC +54 React Components Library

License

MDC-UI is a collection of React components developed by MDC +54. These components are designed to provide enhanced user interface elements for your React applications.

Installation

To install MDC-UI in your project, you can use npm:

npm install mdc-ui

Set Up

Set this logic for the color palette in the src/constants/Color.ts directory. You can change or add any color you want. Take in count if you add for example a new color you should also update the mdc-ui repository.

Create this file in your Next App and add the following code:

export type Color = keyof typeof AVAILABLE_COLORS;

export const AVAILABLE_COLORS = {
    "transparent": {
        "DEFAULT": "transparent",
    },
    "white": {
        "DEFAULT": "#ffffff",
    },
    "black": {
        "DEFAULT": "#000000",
    },
    gray: {
        "50": "#F6F6F6",
        "100": "#F2F2F2",
        "200": "#C6C6C6",
        "300": "#939393",
        "400": "#838383",
        "500": "#4D4D4D",
        "600": "#434343",
        "700": "#2C2C2C",
        "800": "#222222",
        "900": "#181818",
        "DEFAULT": "#838383",
    },
    blue: {
        "100": "#EEF4FF",
        "300": "#6CC6F8",
        "500": "#3F80F1",
        "700": "#3653E8",
        "900": "#2722B7",
        "DEFAULT": "#3F80F1",
    },
    violet: {
        "100": "#EFEAFD",
        "300": "#B9AAF9",
        "500": "#9B86F7",
        "700": "#816AF4",
        "900": "#5B43EA",
        "DEFAULT": "#9B86F7",
    },
    green: {
        "100": "#E2F8ED",
        "300": "#84E1B6",
        "500": "#3CD699",
        "700": "#00CC81",
        "900": "#00B161",
        "DEFAULT": "#3CD699",
    },
    pink: {
        "100": "#FFE7FA",
        "300": "#FFA9F0",
        "500": "#FF60E5",
        "700": "#D946EF",
        "900": "#B900C3",
        'DEFAULT': "#FF60E5",
    },
    yellow: {
        '100': "#FFF8C2",
        '300': "#FFE94E",
        '500': "#FFD62A",
        '700': "#FBA41C",
        '900': "#F87A10",
        'DEFAULT': "#FFD62A",
    },
    red: {
        '100': "#FFDEE4",
        '300': "#F8A0A2",
        '500': "#FF5C5C",
        '700': "#F74342",
        '900': "#C82728",
        'DEFAULT': "#FF5C5C",
    }
} as const;

export const get = (color: Color, shade: string = "DEFAULT") => {
    return AVAILABLE_COLORS ? AVAILABLE_COLORS[color] ? (AVAILABLE_COLORS[color] as any)[shade] ? (AVAILABLE_COLORS[color] as any)[shade] : false : false : false;
}

const hexToRgb = (hex: string) => {
    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
    return result ? {
        r: parseInt(result[1], 16),
        g: parseInt(result[2], 16),
        b: parseInt(result[3], 16)
    } : null;
}

export const getCssVariables = () => {
    const colors = Object.keys(AVAILABLE_COLORS);
    return colors.map(color => {
        const shades = Object.keys(AVAILABLE_COLORS[color as Color]);
        return shades.map(shade => {
            const value = get(color as Color, shade);
            const hexVar = shade !== "DEFAULT" ? `--${color}-${shade}: ${value};` : `--${color}: ${value};`;

            const rgbValue = hexToRgb(value);
            var rgbVar = shade !== "DEFAULT" ? `--${color}-${shade}-rgb: ${rgbValue?.r}, ${rgbValue?.g}, ${rgbValue?.b};` : `--${color}-rgb: ${rgbValue?.r}, ${rgbValue?.g}, ${rgbValue?.b};`;
            rgbVar = rgbValue ? rgbVar : "";

            return `${hexVar} ${rgbVar}`;
        });
    }).flat().join(" ");
}

export const getTailwindColors = () => {
    return AVAILABLE_COLORS;
}

Add the css variables in the src/pages/_app.tsx directory. This will add the :root variables.

import '@/styles/globals.css'
import type { AppProps } from 'next/app'
import { getCssVariables } from '@/constants/Colors'

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
        <style>
            {`
                :root {
                    ${getCssVariables()}
                }
            `}
        </style>
        <Component {...pageProps} />
    </>
  )}

In case you are using Tailwind.css add this in the tailwind.config.js

/** @type {import('tailwindcss').Config} */
extend: {
    colors: {
        ...getTailwindColors(),
    },
}
1.0.87

7 months ago

1.0.86

8 months ago

1.0.85

8 months ago

1.0.80

8 months ago

1.0.84

8 months ago

1.0.83

8 months ago

1.0.82

8 months ago

1.0.81

8 months ago

1.0.79

9 months ago

1.0.78

9 months ago

1.0.77

9 months ago

1.0.76

9 months ago

1.0.75

9 months ago

1.0.74

9 months ago

1.0.73

9 months ago

1.0.72

9 months ago

1.0.71

9 months ago

1.0.70

9 months ago

1.0.69

9 months ago

1.0.68

9 months ago

1.0.67

9 months ago

1.0.66

9 months ago

1.0.65

9 months ago

1.0.64

9 months ago

1.0.63

9 months ago

1.0.62

9 months ago

1.0.61

9 months ago

1.0.60

9 months ago

1.0.59

9 months ago

1.0.58

9 months ago

1.0.57

9 months ago

1.0.56

9 months ago

1.0.55

9 months ago

1.0.54

9 months ago

1.0.53

9 months ago

1.0.52

9 months ago

1.0.51

9 months ago

1.0.50

9 months ago

1.0.42

9 months ago

1.0.41

9 months ago

1.0.40

9 months ago

1.0.39

9 months ago

1.0.38

9 months ago

1.0.37

9 months ago

1.0.36

9 months ago

1.0.35

9 months ago

1.0.34

9 months ago

1.0.33

9 months ago

1.0.32

9 months ago

1.0.31

9 months ago

1.0.30

9 months ago

1.0.29

9 months ago

1.0.28

9 months ago

1.0.26

9 months ago

1.0.25

9 months ago

1.0.24

9 months ago

1.0.23

9 months ago

1.0.22

9 months ago

1.0.21

9 months ago

1.0.20

9 months ago

1.0.19

9 months ago

1.0.18

9 months ago

1.0.17

9 months ago

1.0.16

9 months ago

1.0.15

9 months ago

1.0.14

9 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago