-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
refactor: color scheme #1245 #1253
Conversation
@kkbt0 is attempting to deploy a commit to the pcloud's projects Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hi @kkbt0, thanks for you contribution! If I am understanding you correctly, your work is a useful refactor on the current color system. However, I fail to see how it relates to the original issue. My intention for #1245 is to (visually) adjust the current
You might notice this PR may not fit very well with the plan, and I am deeply sorry that I failed to explain my intentions more clearly in the original issue. Here are some context behind the original issue: #1, #654, #1176. I'd like to hear your thoughts on this. Many thanks |
Well . I also don't kown the best method. I only used default and dark in TailwindCSS . Should it be like this? > https://play.tailwindcss.com/KDVQG5ULlM (This example overlooks .) However, I anticipate that the class length for Hugo's {{ .Content }} typography prose class will be quite lengthy. It'll be a big project. |
I was thinking about something like @tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--color-primary: 247 147 34;
--color-text: 33 33 33;
--color-success: 0 200 81;
--color-info: 51 181 229;
--color-warn: 255 187 51;
--color-error: 254 78 78;
}
:root[class~="dark"] {
--color-primary: 247 147 34;
--color-text: 33 33 33;
--color-success: 0 200 81;
--color-info: 51 181 229;
--color-warn: 255 187 51;
--color-error: 254 78 78;
}
} /** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: "class",
theme: {
colors: {
primary: "rgb(var(--color-primary) / <alpha-value>)",
text: "rgb(var(--color-text) / <alpha-value>)",
success: "rgb(var(--color-success) / <alpha-value>)",
info: "rgb(var(--color-info) / <alpha-value>)",
warn: "rgb(var(--color-warn) / <alpha-value>)",
error: "rgb(var(--color-error) / <alpha-value>)",
transparent: "transparent",
current: "currentColor",
},
} (Reference: https://stackoverflow.com/questions/72117668/tailwind-colors-based-on-dark-mode) And the user can override any of the CSS variables inside the override.scss DoIt/assets/css/_override.scss Line 3 in 0b8fa13
I am not planning to support multiple color themes for now since we are even struggling to coming up with a single color palette for the dark theme. I believe ad hoc customisations for individual color elements will be more useful for the users and easier for us to maintain.
The prose class will indeed be lengthy if we eventually migrate completely to Tailwind, and I am not even sure that's a good idea. But fortunately Tailwind CSS has very good suppport for progressive migration, and it seems to be working quite well integrating with the existing SCSS setup. I am planning to migrate piece by piece lazily rather than all in one go. Specifically, I want to style all new features using Tailwind, and it worked quite well in the past (See https://github.com/HEIGE-PCloud/DoIt/pull/1214/files#diff-b15932692c619f9a334ecb156ac167557c3af214a8a3df8990c09232ac8a5baa). I also want to migrate existing styles to Tailwind when we are refactoring, so I see both #1236 and #1245 as good opportunities for doing so. |
Okay, in the example of stackhoverflow, defining the appearance through CSS variables can also easily increase or decrease the theme. In fact, I like these three themes without considering the CSS file size and the large number of duplicates in the two dark modes.(Especially with the addition of code color parameters, the three theme color variables seem to exceed Github's approximately 1000 lines of colors variables .) So next step we should define all need color variables in a file and use them in tailwind.config.js . Then, step by step, replace the definition of font and background color with class in html . Regarding the issue of Tailwindcss Class being too long, I have tried Unocss Shortcuts . This will put all Tailwindcss classes into a self named class. Just be like https://daisyui.com/ |
Nice, sound good!
I am not very sure on this one. I don't necessarily see "classes being too long" as an issue, if an element requires a lot of styling, then the class name can be long - that's what it takes to express such information. Utilities like Unocss Shortcuts does not really reduce the classes, it just moves it from HTML to the config file, which in my view defeats the purpose of atomic CSS. The whole idea is that when the style and the element is co-located, it minimises the coupling of the styles between different elements - I no longer need to worry whether changing the style of one element might potentially break the style of another. I think the right way to reduce duplication in styles is to use partial templates to extract elements as reusable "components" but keep the class names as is. Also, I don't really think it's necessary to completely move to Tailwind, if using prose to style Content is a pain, we can just keep the current SCSS setup and we can have the best of both worlds. Reference https://tailwindcss.com/docs/reusing-styles#extracting-components-and-partials |
In some extreme cases, the number of classes can reach 20-30. for example a button in https://catalyst.tailwindui.com/ . <div class="relative h-full w-full rounded-xl bg-white
shadow-[0px_0px_0px_1px_rgba(9,9,11,0.07),0px_2px_2px_0px_rgba(9,9,11,0.05)]
dark:bg-zinc-900 dark:shadow-[0px_0px_0px_1px_rgba(255,255,255,0.1)]
dark:before:pointer-events-none dark:before:absolute
dark:before:-inset-px dark:before:rounded-xl
dark:before:shadow-[0px_2px_8px_0px_rgba(0,_0,_0,_0.20),_0px_1px_0px_0px_rgba(255,_255,_255,_0.06)_inset]
forced-colors:outline"> Actually, there are a lot of class when I am writing a grid element . This is indeed easy to write , but I'm not sure if this is highly readable and easy to maintain code. <div class="bg-white dark:bg-dark
w-full h-full overflow-hidden rounded-lg
border border-transparent
flex flex-col justify-center
@container
col-span-2 row-span-4 aspect-1/2
md:col-span-1 md:row-span-2 md:aspect-1/2
card-transition"> Or create a template partia.After writing blog info card component, it should be like this. https://github.com/saicaca/fuwari/blob/main/src/components/PostCard.astro |
I understand your idea, instead of writing <div class="<a lot of classes>"> You write <div class="custom-div"> and .custom-div {
@apply <a lot of classes>
} My point is that this does not reduce the amount of classes we write, it merely moves it from one place to another. Now when we want to change the style for the div, we still need to deal with a very long list of classes - just in a different file. But even worse, now we don't know whether someone else is using the One potential use case is that you might use that same div twice on the same page <div class="<a lot of classes>"></div>
<div class="<a lot of classes>"></div> Now when we want to adjust its style, we need to make sure we have adjusted every single div that uses the same style. In which case we can just extract that div into a partial as Tailwind's docs suggested. Or even better, we can leverage Hugo to work with variables like: {{- $style := "<a lot of classes>" -}}
<div class="{{- $style -}}"></div>
<div class="{{- $style -}}"></div> |
In fact , my code likely be like this <div class="m-c-basic fc-jc g-2-4"> .m-c-basic {
@apply bg-white dark:bg-dark w-full h-full overflow-hidden rounded-lg border border-transparent card-transition shadow-[0px_0px_0px_1px_rgba(9,9,11,0.07),0px_2px_2px_0px_rgba(9,9,11,0.05)] dark:bg-zinc-900 dark:shadow-[0px_0px_0px_1px_rgba(255,255,255,0.1)] @container
}
.fc-jc {
@apply flex flex-col justify-center
}
.g-2-4 {
@apply col-span-2 row-span-4 aspect-1/2
}
.g-md-1-2 {
@apply md:col-span-1 md:row-span-2 md:aspect-1/2
} CSS will be like .m-c-basic {
width: 100%;
height: 100%;
display: flex;
border-width: 1px;
border-color: transparent;
border-radius: 0.5rem;
container-type: inline-size;
....
} Because this element needs to appear over ten times in the grid. So I abstracted and reused a portion of the code.Perhaps when changing shadows, there is no need to search and replace them in bulk. But I use @apply just to make things look “cleaner” .This may violate the principles in the tailwindcss document. <div class="m-c-basic fc-jc g-2-4">
<div class="bg-white dark:bg-dark
w-full h-full overflow-hidden rounded-lg
border border-transparent
flex flex-col justify-center
@container
col-span-2 row-span-4 aspect-1/2
md:col-span-1 md:row-span-2 md:aspect-1/2
shadow-[0px_0px_0px_1px_rgba(9,9,11,0.07),0px_2px_2px_0px_rgba(9,9,11,0.05)] dark:bg-zinc-900 dark:shadow-[0px_0px_0px_1px_rgba(255,255,255,0.1)]
card-transition"> Which one is better ? |
Ok, now let's say i want to change
Is it really "clean"? We still have this long and "unclean" Here is what I would probably do, I would define a custom shadow in the config to make the shadow less error prone. I would also set up the bg-color with CSS variable so I don't need to worry about trivial dark variants. If the |
In fact, this is probably an imitation of Bootstrap. The bootstrap code style is roughly like this. <div class="card shadow position-relative h-100 rounded-home-item"></div> Or this is a molecule composed of several atoms. Just like a |
The good thing about Such molecules can be useful from time to time, but I view it in a case by case way, and we shall definitely make them immutable if we decide to create our own. I agree abstractions like
can be useful, but |
That is what i want to say. Sometimes we need molecules . The specific amount of aggregation depends on the project requirements. |
assets/css/main.css
Outdated
--code-background-color-darken-3: #ededed; | ||
--code-background-color-darken-5: #e8e8e8; | ||
--code-background-color-darken-6: #e6e6e6; | ||
--code-background-color-darken-8: #e1e1e1; | ||
--code-background-color-darken-10: gainsboro; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to hard code all the darken colors here?
Can something like this work?
.style {
--color: #000;
color: darken(var(--color), 3%);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
darken is a scss function . color: darken(var(--color), 3%);
ERROR TOCSS: failed to transform "/css/style.scss" (text/x-scss): "/root/DoIt/assets/css/_variables.scss:107:34": argument
$color
ofdarken($color, $amount)
must be a color
Built in 890 ms
Error: error building site: TOCSS: failed to transform "/css/style.scss" (text/x-scss): "/root/DoIt/assets/css/_variables.scss:107:34": argument$color
ofdarken($color, $amount)
must be a color
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mabey we should use hsl
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hsl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not using darken-8 and darken-10 anywhere right? I can look into each individual usage point and pick an explicit color for each of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
background: darken($code-background-color, 8%); |
DoIt/assets/css/_partial/_single/_code.scss
Line 130 in a3970ec
background-color: darken($code-background-color, 10%); |
so /root/DoIt/assets/css/tailwind.css L129
--code-background-color-code-header: var(--code-background-color-darken-8);
--code-background-color-code-hl: gainsboro;
should be
--code-background-color-code-hl: var(--code-background-color-darken-10);
It is a err . And dark black theme don't use them ( 8 and 10 ).
$global-link-color: #161209 !default; | ||
$global-link-color-dark: #a9a9b3 !default; | ||
$global-link-color-black: #d9d9d9 !default; | ||
$global-link-color: var(--global-link-color) !default; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been thinking about this, at this point do we really need the mapping from CSS variables to SCSS variables? Is there anything stopping us from just writing
.style {
color: var(--color);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this at first, but then I kept a mapping. Manage all colors in one SCSS file. I think it's easy to advance and retreat.
This would be useful for refactoring to reduce the same color variables, and to modify them using a format similar to "-- primary".
* refactor: color scheme * refactor: colors in Tailwind Config * fix: scss variables use error * feat: partially adopt Prime Design for the dark theme * feat: pick selection color * feat: pick link color * feat: pick codeblock, table, blockquote color * feat: pick more colors * refactor: remove black theme * fix: code background color * refactor: extract primitive colors * refactor: use primitive colors in tailwind config * chore: use --verbose * chore: sync github CI build step --------- Co-authored-by: PCloud <[email protected]>
* refactor: codeblock * feat: implement wrap and toggle open animation * chore: handle max-height calculation correctly * chore: remove unnecessary js * chore: remove clipboardjs * feat: use icons * feat: add text wrap icon * feat: add style to icons * refactor: switch to typescript * chore: add global declaration * chore: optimise image resize method * fix: sharer wechat and mastodon icon Close #1247 * Disable autoplay (#1249) * Improve the `bilibili` shortcode with more options (#1250) * add variables * finished the initial dev of bilibili improvement next is documentation * rearrange bilibili options * added documentation for improved bilibili shortcode * fluent chinese * chore: disableHTTPCache for dev env * refactor: color scheme #1245 (#1253) * refactor: color scheme * refactor: colors in Tailwind Config * fix: scss variables use error * feat: partially adopt Prime Design for the dark theme * feat: pick selection color * feat: pick link color * feat: pick codeblock, table, blockquote color * feat: pick more colors * refactor: remove black theme * fix: code background color * refactor: extract primitive colors * refactor: use primitive colors in tailwind config * chore: use --verbose * chore: sync github CI build step --------- Co-authored-by: PCloud <[email protected]> * chore: re-enable counter * fix: syntax highlightning * chore: format code * fix(style): do not wrap line number * feat: make line numbers fix position * chore: bad idea, revert * refactor: move all js logic into theme.ts * feat: support copy icon states * feat: implement line number toggle * feat: move all JavaScript to theme.ts * feat: support custom title * feat: init all states * feat: support maxShownLines * fix: correct color scheme * chore: switch icon back to svg * feat: expand code blocks before print * deprecate copy option * feat: add titles to buttons * feat: add docs * feat: support wrap option --------- Co-authored-by: CXwudi <[email protected]> Co-authored-by: 恐咖兵糖 <[email protected]>
for issue #1245
Change the theme color switching scheme to switch color variables. This is beneficial for removing or adding color schemes at a very small cost.
This may bring compatibility issues, but most browsers now support CSS variables.
https://developer.mozilla.org/zh-CN/docs/Web/CSS/var
Or licensed for use https://github.com/jhildenbiddle/css-vars-ponyfill Compatible with old browsers.
Most styles should be the same, with known differences being code block themes. reference
The code block uses GitHub and OneDark themes instead of three very long variables.