Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable different color input #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");

const path = require('path');
module.exports = {
stories: [
"../src/**/*.stories.mdx",
Expand All @@ -24,6 +24,22 @@ module.exports = {
},
},
],
webpackFinal: async (config) => {
config.module.rules.push({
test: /\,css&/,
use: [
{
loader: "postcss-loader",
options: {
ident: "postcss",
plugins: [require("tailwindcss"), require("autoprefixer")],
},
},
],
include: path.resolve(__dirname, "../"),
});
return config;
},
framework: "@storybook/react",
resolve: {
plugins: [new TsconfigPathsPlugin({})],
Expand Down
1 change: 1 addition & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../src/index.css'
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
Expand Down
17 changes: 8 additions & 9 deletions src/hooks/useCustomSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
setDefaultSourceToken,
setDefaultDestToken,
} from "../state/customSettingsSlice";
import { formatRGB } from "../utils";

// To set custom chains, tokens, default values passed as props
export const useCustomSettings = (props: WidgetProps) => {
Expand Down Expand Up @@ -54,42 +53,42 @@ export const useCustomSettings = (props: WidgetProps) => {
customize?.accent &&
document.documentElement.style.setProperty(
"--socket-widget-accent-color",
formatRGB(customize.accent)
customize.accent
);
customize?.onAccent &&
document.documentElement.style.setProperty(
"--socket-widget-on-accent-color",
formatRGB(customize.onAccent)
customize.onAccent
);
customize?.primary &&
document.documentElement.style.setProperty(
"--socket-widget-primary-color",
formatRGB(customize.primary)
customize.primary
);
customize?.secondary &&
document.documentElement.style.setProperty(
"--socket-widget-secondary-color",
formatRGB(customize.secondary)
customize.secondary
);
customize?.text &&
document.documentElement.style.setProperty(
"--socket-widget-primary-text-color",
formatRGB(customize.text)
customize.text
);
customize?.secondaryText &&
document.documentElement.style.setProperty(
"--socket-widget-secondary-text-color",
formatRGB(customize.secondaryText)
customize.secondaryText
);
customize?.interactive &&
document.documentElement.style.setProperty(
"--socket-widget-interactive",
formatRGB(customize.interactive)
customize.interactive
);
customize?.onInteractive &&
document.documentElement.style.setProperty(
"--socket-widget-on-interactive",
formatRGB(customize.onInteractive)
customize.onInteractive
);
}, [customize]);
};
18 changes: 9 additions & 9 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ input[type="number"] {

@layer base {
:root {
--socket-widget-accent-color: 239, 51, 116;
--socket-widget-on-accent-color: 255, 255, 255;
--socket-widget-primary-color: 255, 255, 255;
--socket-widget-secondary-color: 241, 245, 249;
--socket-widget-primary-text-color: 0, 0, 0;
--socket-widget-secondary-text-color: 68, 68, 68;
--socket-widget-outline-color: 208, 208, 208;
--socket-widget-interactive: 241, 245, 249;
--socket-widget-on-interactive: 10,10,10;
--socket-widget-accent-color: rgb(239, 51, 116);
--socket-widget-on-accent-color: rgb(255, 255, 255);
--socket-widget-primary-color: rgb(255, 255, 255);
--socket-widget-secondary-color: rgb(241, 245, 249);
--socket-widget-primary-text-color: rgb(0, 0, 0);
--socket-widget-secondary-text-color: rgb(68, 68, 68);
--socket-widget-outline-color: rgb(208, 208, 208);
--socket-widget-interactive: rgb(241, 245, 249);
--socket-widget-on-interactive: rgb(10,10,10);
}
}
41 changes: 17 additions & 24 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
/** @type {import('tailwindcss').Config} */

function withOpacity(variableName) {
return ({ opacityValue }) => {
if (opacityValue !== undefined)
return `rgba(var(${variableName}), ${opacityValue})`;
else return `rgb(var(${variableName}))`;
};
}

module.exports = {
enabled: process.env.NODE_ENV === "publish",
Expand All @@ -15,31 +8,31 @@ module.exports = {
extend: {
textColor: {
widget: {
accent: withOpacity("--socket-widget-accent-color"),
onAccent: withOpacity("--socket-widget-on-accent-color"),
primary: withOpacity("--socket-widget-primary-text-color"),
'primary-main': withOpacity("--socket-widget-primary-color"),
secondary: withOpacity("--socket-widget-secondary-text-color"),
outline: withOpacity("--socket-widget-outline-color"),
'on-interactive': withOpacity("--socket-widget-on-interactive")
accent: "var(--socket-widget-accent-color)",
onAccent: "var(--socket-widget-on-accent-color)",
primary: "var(--socket-widget-primary-text-color)",
'primary-main':"var(--socket-widget-primary-color)",
secondary: "var(--socket-widget-secondary-text-color)",
outline: "var(--socket-widget-outline-color)",
'on-interactive': "var(--socket-widget-on-interactive)"
},
},
backgroundColor: {
widget: {
accent: withOpacity("--socket-widget-accent-color"),
primary: withOpacity("--socket-widget-primary-color"),
secondary: withOpacity("--socket-widget-secondary-color"),
outline: withOpacity("--socket-widget-outline-color"),
interactive: withOpacity('--socket-widget-interactive')
accent: "var(--socket-widget-accent-color)",
primary: "var(--socket-widget-primary-color)",
secondary: "var(--socket-widget-secondary-color)",
outline: "var(--socket-widget-outline-color)",
interactive: 'var(--socket-widget-interactive)'
},
},
borderColor: {
widget: {
accent: withOpacity("--socket-widget-accent-color"),
primary: withOpacity("--socket-widget-primary-color"),
secondary: withOpacity("--socket-widget-secondary-color"),
"secondary-text": withOpacity("--socket-widget-secondary-text-color"),
outline: withOpacity("--socket-widget-outline-color"),
accent: "var(--socket-widget-accent-color)",
primary:"var(--socket-widget-primary-color)",
secondary: "var(--socket-widget-secondary-color)",
"secondary-text": "var(--socket-widget-secondary-text-color)",
outline: "var(--socket-widget-outline-color)",
},
},
width: {
Expand Down