-
-
Notifications
You must be signed in to change notification settings - Fork 247
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: add tailwind + shadcn/ui. #888
Conversation
now, |
Is this going to be quite a big effort to make everything look the same/similar? I'm not familiar with how it can be converted though. @zeroliu is the expert here I'll wait for his recommendation. |
e031a19
to
a848f01
Compare
I already delete |
Awesome job! The UI now looks correct to me. One concern is that the bundle size is up significantly from 5MB+ to 21MB+. Is there any way we can make it smaller? Tailwind purging? |
ea9182c
to
22a10f4
Compare
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.
Left some more comments. Looking good overall! Looking forward to using tailwindCSS in the near future
tailwind.config.js
Outdated
preflight: false, | ||
}, | ||
theme: { | ||
extend: { |
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.
can we not extend but redefine all the tokens? Otherwise, people can still use predefined tailwind tokens without realizing that it's not connected to obsidian CSS variables. We can also turn on this eslint rule to enforce only supported classnames are used in the code base: https://github.com/francoismassart/eslint-plugin-tailwindcss/blob/master/docs/rules/no-custom-classname.md
src/components/ui/input.tsx
Outdated
|
||
import { cn } from "@/lib/utils"; | ||
|
||
const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>( |
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.
not blocking this PR but maybe we can look into React 19 and use the ref
props now that it's officially GA. Maintaining forwardRef for RadixUI can be pretty tedious.
@Emt-lin Thanks for the sync today! When you get a chance, could you address zero's comments? And I think this should be ready to merge after! |
@@ -121,7 +121,8 @@ export enum EmbeddingModelProviders { | |||
OPENAI = "openai", | |||
COHEREAI = "cohereai", | |||
GOOGLE = "google", | |||
AZURE_OPENAI = "azure_openai", | |||
// AZURE_OPENAI = "azure_openai", | |||
AZURE_OPENAI = "azure openai", |
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.
does it belong to this PR?
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.
yeah, it's a separate commit and @logancyang also learn about this.
src/styles/tailwind.css
Outdated
body { | ||
/* preDefine CSS variables in Obsidian.(https://docs.obsidian.md/Reference/CSS+variables/Foundations/Colors) */ | ||
/*Primary background*/ | ||
--ob-bg-primary: var(--background-primary); |
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 redefine obsidian CSS with --ob-bg
prefix?
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 think that redefine obsidian CSS will more clarify. I want to provide out-of-the-box functionality, when we add some shadcn/ui component.
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.
Do you have any specific features in mind that would require us to break apart from the default css variables? This is an additional layer that we have to maintain. If we want to apply a new obsidian css variable that is not included in this PR, the process of adding it would require us to:
- Make a copy of the css variable
- Create a new tailwind token with a different semantic value
The more undocumented overhead we add, the more difficult it is for new contributors to make changes.
If you feel strongly that creating our own semantic token is necessary, and it can simplify the component library adoption, I'm supportive of that. However, we should at least consider not adding another layer of complexity and use the obsidian css variable directly.
Also worth noting that any external CSS variable that we introduce will not be compatible with the obsidian theme, which can be a dealbreaker for some users.
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 am merely listing all the obsidian css variables rather than defining a new set of variables.
If we want to apply a new obsidian css variable
I have listed most of the color css variables.
The more undocumented overhead we add, the more difficult it is for new contributors to make changes.
When a new contributor joins, he/her doesn't need to do anything extra work, and he/her doesn't need to care about these.
He can use existing components or download new ones from the shadcn/ui, and then he doesn't need to do anything, the component will automatically change with the theme.
src/styles/tailwind.css
Outdated
} | ||
} | ||
|
||
/* this layer for overwrite Obsidian default css style(file: app.css) and theme css style */ |
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 don't think we should be touching the default component style as it will affect UI outside of obsidian-copilot
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.
@zeroliu It doesn't affect UI outside of obsidian-copilot, It only work for copilot ui.
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.
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.
Just checked again, this is not a new problem introduced by this PR. The existing style can also affect other plugins. If I add warning-message
to my plugin element and load the master version copilot, my element will also be affected. I sent a question to the obsidian discord to understand how style isolation works in obsidian. It seems very error-prone.
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.
import { colorOpacityPlugin } from "./src/lib/plugins/colorOpacityPlugin"; | ||
import colors from "tailwindcss/colors"; | ||
|
||
/** @type {import("tailwindcss").Config} */ |
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 can use tailwind.config.ts to get full type support instead of this type comment
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.
The JS type documentation also provides full type support. Therefore, both TS and JS can work.
tailwind.config.js
Outdated
black: colors.black, | ||
white: colors.white, |
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.
what's the use case of black, white, red, yellow? Are there existing semantic tokens that can replace 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.
I think we don't need full semantic tokens support. It only base color. We don't need to fully trap ourselves in the concept of Obsidian. It's also tailwind project.
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.
Using colors like white and black directly will likely to cause dark theme to break, as well as causing unexpected edge cases for people using non default themes. Do you have a good way to avoid these potential breakage?
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 test some top theme. It's work well in light/dark mode. Dialog overlay will use the black color. I think you can pull up pr #955, you will know about something.
3: "var(--size-4-3)", | ||
4: "var(--size-4-4)", | ||
5: "var(--size-4-5)", | ||
5.5: "calc(var(--size-4-5) + 2px)", |
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.
When do we need this token? It doesn't feel necessary to introduce a new token that needs to calculate a new value outside of the obsidian design system?
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.
In the button component, I need the define of 5.5
, others else can be removed.
src/settings/model.ts
Outdated
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.
does this change belong to this PR?
@logancyang @zeroliu please review this pr. |
tailwind.config.js
Outdated
70: "var(--color-base-70)", | ||
100: "var(--color-base-100)", | ||
}, | ||
// red: "var(--color-red)", |
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.
can we not use the obsidian defined red and yellow 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.
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.
This is the principle of limiting the choice for developers and consistency.
Regarding limiting the choice, TailwindCSS is a generic CSS library; its goal is to allow people to build any applications. TW has to provide not only a complete set of primitive tokens and semantic tokens and let people decide what they want. Our goal is not to replicate TailwindCSS tokens but to tailor them down to what the copilot plugin may need. We don't want developers to add tokens like bg-color-red-50
without a specific reason in the plugin because #fef2f2 is not a color in either the obsidian design system or copilot design.
For consistency, this PR defines red, yellow, and black differently from the rest of the colors, making it harder to predict when applying color tokens. We would either go with Tailwind color tokens entirely or choose only obsidian colors. Staying in the middle will make decision-making harder in the future.
Unless we have a concrete use case that the obsidian color tokens cannot fit and it adds value to the copilot design, we should refrain from introducing new tokens.
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.
Staying in the middle will make decision-making harder in the future.
agree.
But Why we need red color? Isn't it a primitive color? It's not a semantic token.
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.
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.
This is the callout component used in the obsidian app and site.
It uses --callout-warning which is --color-orange-rgb. The background is rgba(var(--callout-warning), 0.1)). There is no specific token for it.
My obsidian tailwind project didn't include all the component tokens from obsidian yet. You can add this token to your PR. Then you can build it as bg-callout-warning/10
and text-callout-warning
. Here's the reference https://docs.obsidian.md/Reference/CSS+variables/Editor/Callout
Support out-of-the-box the Tailwind + shadcn/ui functionality