Skip to content

Commit 4663318

Browse files
fix: ShadCN Tailwind scoping (#847)
* Added "bn-" prefix to ShadCN Tailwind classes * Added missed prefix * Small fixes * Added CSS class to `bn-container` for each UI lib to scope styles * Removed redundant CSS prefixes and fixed prefix names * Added comment
1 parent cadf35f commit 4663318

37 files changed

+241
-205
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ariakit/src/ariakitStyles.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ responsible for the majority of the styling. */
140140
padding-bottom: 7px;
141141
}
142142

143-
.bn-ak-menu:not(:focus) .bn-ak-menu-item:not(:focus)[aria-expanded="true"] {
143+
.bn-ak-menu:not(:focus)
144+
.bn-ak-menu-item:not(:focus)[aria-expanded="true"] {
144145
background-color: hsl(204 4% 0% / 7.5%);
145146
color: currentColor;
146147
}

packages/ariakit/src/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { BlockSchema, InlineContentSchema, StyleSchema } from "@blocknote/core";
1+
import {
2+
BlockSchema,
3+
InlineContentSchema,
4+
mergeCSSClasses,
5+
StyleSchema,
6+
} from "@blocknote/core";
27
import {
38
BlockNoteViewRaw,
49
Components,
@@ -95,9 +100,14 @@ export const BlockNoteView = <
95100
>(
96101
props: ComponentProps<typeof BlockNoteViewRaw<BSchema, ISchema, SSchema>>
97102
) => {
103+
const { className, ...rest } = props;
104+
98105
return (
99106
<ComponentsContext.Provider value={components}>
100-
<BlockNoteViewRaw {...props} />
107+
<BlockNoteViewRaw
108+
className={mergeCSSClasses("bn-ariakit", className || "")}
109+
{...rest}
110+
/>
101111
</ComponentsContext.Provider>
102112
);
103113
};

packages/ariakit/src/style.css

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,22 @@
2828
gap: 0.5rem;
2929
}
3030

31-
.bn-tab-panel {
31+
.bn-ariakit .bn-tab-panel {
3232
align-items: center;
3333
display: flex;
3434
flex-direction: column;
3535
gap: 0.5rem;
3636
}
3737

38-
.bn-file-input {
38+
.bn-ariakit .bn-file-input {
3939
max-width: 100%;
4040
}
4141

4242
.bn-ak-button {
4343
outline-style: none;
4444
}
4545

46-
.bn-ak-menu-item[aria-selected="true"],
47-
.bn-ak-menu-item:hover {
46+
.bn-ak-menu-item[aria-selected="true"], .bn-ak-menu-item:hover {
4847
background-color: hsl(204 100% 40%);
4948
color: hsl(204 20% 100%);
5049
}
@@ -53,12 +52,11 @@
5352
display: flex;
5453
}
5554

56-
.bn-dropdown {
55+
.bn-ariakit .bn-dropdown {
5756
overflow: visible;
5857
}
5958

60-
.bn-suggestion-menu,
61-
.bn-color-picker-dropdown {
59+
.bn-ariakit .bn-suggestion-menu, .bn-ariakit .bn-color-picker-dropdown {
6260
overflow: scroll;
6361
}
6462

@@ -85,7 +83,7 @@
8583
padding-inline: 4px;
8684
}
8785

88-
.bn-side-menu {
86+
.bn-ariakit .bn-side-menu {
8987
align-items: center;
9088
display: flex;
9189
justify-content: center;
@@ -97,35 +95,34 @@
9795
width: fit-content;
9896
}
9997

100-
.bn-panel-popover {
98+
.bn-ariakit .bn-panel-popover {
10199
background-color: transparent;
102100
border: none;
103101
box-shadow: none;
104102
}
105103

106-
.bn-table-handle {
104+
.bn-ariakit .bn-table-handle {
107105
height: fit-content;
108106
padding: 0;
109107
width: fit-content;
110108
}
111109

112-
.bn-side-menu,
113-
.bn-table-handle {
110+
.bn-ariakit .bn-side-menu,
111+
.bn-ariakit .bn-table-handle {
114112
color: gray;
115113
}
116114

117115
.bn-ak-button:where(.dark, .dark *) {
118116
color: hsl(204 20% 100%);
119117
}
120118

121-
.bn-ak-tab,
122-
.bn-file-input {
119+
.bn-ak-tab, .bn-ariakit .bn-file-input {
123120
background-color: transparent;
124121
color: black;
125122
}
126123

127124
.bn-ak-tab:where(.dark, .dark *),
128-
.bn-file-input:where(.dark, .dark *) {
125+
.bn-ariakit .bn-file-input:where(.dark, .dark *) {
129126
color: white;
130127
}
131128

packages/mantine/src/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { BlockSchema, InlineContentSchema, StyleSchema } from "@blocknote/core";
1+
import {
2+
BlockSchema,
3+
InlineContentSchema,
4+
mergeCSSClasses,
5+
StyleSchema,
6+
} from "@blocknote/core";
27
import {
38
BlockNoteViewRaw,
49
Components,
@@ -122,7 +127,7 @@ export const BlockNoteView = <
122127
};
123128
}
124129
) => {
125-
const { theme, ...rest } = props;
130+
const { className, theme, ...rest } = props;
126131

127132
const existingContext = useBlockNoteContext();
128133
const systemColorScheme = usePrefersColorScheme();
@@ -160,12 +165,13 @@ export const BlockNoteView = <
160165
{/* as proposed here: https://github.com/orgs/mantinedev/discussions/5685 */}
161166
<MantineProvider
162167
theme={mantineTheme}
163-
cssVariablesSelector=".bn-container"
168+
cssVariablesSelector=".bn-mantine"
164169
// This gets the element to set `data-mantine-color-scheme` on. Since we
165170
// don't need this attribute (we use our own theming API), we return
166171
// undefined here.
167172
getRootElement={() => undefined}>
168173
<BlockNoteViewRaw
174+
className={mergeCSSClasses("bn-mantine", className || "")}
169175
theme={typeof theme === "object" ? undefined : theme}
170176
{...rest}
171177
ref={ref}

packages/mantine/src/mantineStyles.css

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,50 +89,50 @@
8989
(src: https://github.com/mantinedev/mantine/blob/master/packages/%40mantine/core/src/core/MantineProvider/global.css)
9090
but with styles set on `body` and `html` instead set on `bn-container`, as
9191
well as other minor changes. */
92-
.bn-container *, .bn-container :after, .bn-container :before {
92+
.bn-mantine *, .bn-mantine :after, .bn-mantine :before {
9393
box-sizing: border-box
9494
}
9595

96-
.bn-container button,
97-
.bn-container select {
96+
.bn-mantine button,
97+
.bn-mantine select {
9898
text-transform: none
9999
}
100100

101101
@media screen and (max-device-width: 500px) {
102-
.bn-container {
102+
.bn-mantine {
103103
-webkit-text-size-adjust: 100%
104104
}
105105
}
106106

107107
@media (prefers-reduced-motion: reduce) {
108-
.bn-container [data-respect-reduced-motion] [data-reduce-motion] {
108+
.bn-mantine [data-respect-reduced-motion] [data-reduce-motion] {
109109
animation: none;
110110
transition: none
111111
}
112112
}
113113

114-
.bn-container [data-mantine-color-scheme=dark] .mantine-dark-hidden, .bn-container [data-mantine-color-scheme=light] .mantine-light-hidden {
114+
.bn-mantine [data-mantine-color-scheme=dark] .mantine-dark-hidden, .bn-mantine [data-mantine-color-scheme=light] .mantine-light-hidden {
115115
display: none
116116
}
117117

118-
.bn-container .mantine-focus-auto:focus-visible {
118+
.bn-mantine .mantine-focus-auto:focus-visible {
119119
outline: calc(.125rem * var(--mantine-scale)) solid var(--mantine-primary-color-filled);
120120
outline-offset: calc(.125rem * var(--mantine-scale))
121121
}
122122

123-
.bn-container .mantine-focus-always:focus {
123+
.bn-mantine .mantine-focus-always:focus {
124124
outline: calc(.125rem * var(--mantine-scale)) solid var(--mantine-primary-color-filled);
125125
outline-offset: calc(.125rem * var(--mantine-scale))
126126
}
127127

128-
.bn-container .mantine-focus-never:focus {
128+
.bn-mantine .mantine-focus-never:focus {
129129
outline: none
130130
}
131131

132-
.bn-container .mantine-active:active {
132+
.bn-mantine .mantine-active:active {
133133
transform: translateY(calc(.0625rem * var(--mantine-scale)))
134134
}
135135

136-
.bn-container[dir=rtl] .mantine-rotate-rtl {
136+
.bn-mantine[dir=rtl] .mantine-rotate-rtl {
137137
transform: rotate(180deg)
138138
}

0 commit comments

Comments
 (0)