Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix(nc-gui): font weight issue if we use custom fontSize windicss variables

Ramesh Mane4ad441ac7575
diff --git a/packages/nc-gui/assets/nc-typography-plugin.ts b/packages/nc-gui/assets/nc-typography-plugin.ts
new file mode 100644
index 0000000000..2dc3196e6d
--- /dev/null
+++ b/packages/nc-gui/assets/nc-typography-plugin.ts
@@ -0,0 +1,45 @@
+import plugin from 'windicss/plugin'
+
+const fontStyleMap: Record<string, [string, { lineHeight: string; letterSpacing?: string; fontWeight: number }]> = {
+ heading1: ['64px', { lineHeight: '92px', letterSpacing: '-0.02rem', fontWeight: 700 }],
+ heading2: ['40px', { lineHeight: '64px', letterSpacing: '-0.02rem', fontWeight: 700 }],
+ heading3: ['24px', { lineHeight: '36px', letterSpacing: '-0.02rem', fontWeight: 700 }],
+ subHeading1: ['20px', { lineHeight: '32px', letterSpacing: '-0.02rem', fontWeight: 700 }],
+ subHeading2: ['16px', { lineHeight: '24px', letterSpacing: '-0.02rem', fontWeight: 700 }],
+ bodyLg: ['16px', { lineHeight: '28px', letterSpacing: '-0.02rem', fontWeight: 500 }],
+ bodyLgBold: ['16px', { lineHeight: '28px', letterSpacing: '-0.02rem', fontWeight: 700 }],
+ body: ['14px', { lineHeight: '24px', fontWeight: 500 }],
+ bodyBold: ['14px', { lineHeight: '24px', fontWeight: 700 }],
+ bodyDefaultSm: ['13px', { lineHeight: '18px', fontWeight: 500 }],
+ bodyDefaultSmBold: ['13px', { lineHeight: '18px', fontWeight: 700 }],
+ bodySm: ['12px', { lineHeight: '18px', fontWeight: 500 }],
+ bodySmBold: ['12px', { lineHeight: '18px', fontWeight: 700 }],
+ caption: ['14px', { lineHeight: '20px', fontWeight: 500 }],
+ captionBold: ['14px', { lineHeight: '20px', fontWeight: 700 }],
+ captionSm: ['12px', { lineHeight: '14px', fontWeight: 500 }],
+ captionSmBold: ['12px', { lineHeight: '14px', fontWeight: 700 }],
+ captionXs: ['10px', { lineHeight: '14px', fontWeight: 500 }],
+ captionXsBold: ['10px', { lineHeight: '14px', fontWeight: 700 }],
+ captionDropdownDefault: ['13px', { lineHeight: '20px', fontWeight: 650 }],
+ sidebarDefault: ['14px', { lineHeight: '20px', fontWeight: 650 }],
+ sidebarSelected: ['14px', { lineHeight: '20px', fontWeight: 650 }],
+}
+
+export default plugin(({ addDynamic, addUtilities }) => {
+ const utils: Record<string, any> = {}
+
+ Object.entries(fontStyleMap).forEach(([key, [fontSize, opts]]) => {
+ utils[`.text-${key}`] = {
+ 'font-size': fontSize,
+ 'line-height': opts.lineHeight,
+ ...(opts.letterSpacing ? { 'letter-spacing': opts.letterSpacing } : {}),
+ 'font-weight': `${opts.fontWeight}`,
+ }
+ })
+
+ addUtilities(utils, {
+ layer: 'components',
+ variants: ['responsive'],
+ completions: Object.keys(fontStyleMap).map((k) => `text-${k}`), // <-- this enables autocomplete in IDE
+ })
+})
diff --git a/packages/nc-gui/assets/style.scss b/packages/nc-gui/assets/style.scss
index 59c0eb29ef..c7d2c54abe 100644
--- a/packages/nc-gui/assets/style.scss
+++ b/packages/nc-gui/assets/style.scss
@@ -24,37 +24,6 @@
}
}
-.text-heading1,
-.text-heading2,
-.text-heading3,
-.text-subHeading1,
-.text-subHeading2,
-.text-bodyLgBold,
-.text-bodyBold,
-.text-bodyDefaultSmBold,
-.text-bodySmBold,
-.text-captionBold,
-.text-captionSmBold,
-.text-captionXsBold {
- @apply font-700;
-}
-
-.text-bodyLg,
-.text-body,
-.text-bodyDefaultSm,
-.text-bodySm,
-.text-caption,
-.text-captionSm,
-.text-captionXs {
- @apply font-500;
-}
-
-.text-captionDropdownDefault,
-.text-sidebarDefault,
-.text-sidebarSelected {
- @apply font-750; /* Original font weight 650 */
-}
-
* {
font-synthesis: none;
}
diff --git a/packages/nc-gui/windi.config.ts b/packages/nc-gui/windi.config.ts
index 0c661db905..9c7578ab05 100644
--- a/packages/nc-gui/windi.config.ts
+++ b/packages/nc-gui/windi.config.ts
@@ -11,6 +11,8 @@ import animations from '@windicss/plugin-animations'
// @ts-expect-error no types for plugin-question-mark
import questionMark from '@windicss/plugin-question-mark'
+import ncTypographyPlugin from './assets/nc-typography-plugin'
+
import {
theme as colors,
themeColors,
@@ -59,6 +61,7 @@ export default defineConfig({
'text-grey',
],
plugins: [
+ ncTypographyPlugin,
scrollbar,
animations,
questionMark,
@@ -113,28 +116,6 @@ export default defineConfig({
tiny: ['11px', '14px'],
small: ['13px', '16px'],
small1: ['13px', '18px'],
- heading1: ['64px', { lineHeight: '92px', letterSpacing: '-0.02rem' }],
- heading2: ['40px', { lineHeight: '64px', letterSpacing: '-0.02rem' }],
- heading3: ['24px', { lineHeight: '36px', letterSpacing: '-0.02rem' }],
- subHeading1: ['20px', { lineHeight: '32px', letterSpacing: '-0.02rem' }],
- subHeading2: ['16px', { lineHeight: '24px', letterSpacing: '-0.02rem' }],
- bodyLg: ['16px', { lineHeight: '28px', letterSpacing: '-0.02rem' }],
- bodyLgBold: ['16px', { lineHeight: '28px', letterSpacing: '-0.02rem' }],
- body: ['14px', { lineHeight: '24px' }],
- bodyBold: ['14px', { lineHeight: '24px' }],
- bodyDefaultSm: ['13px', { lineHeight: '18px' }],
- bodyDefaultSmBold: ['13px', { lineHeight: '18px' }],
- bodySm: ['12px', { lineHeight: '18px' }],
- bodySmBold: ['12px', { lineHeight: '18px' }],
- caption: ['14px', { lineHeight: '20px' }],
- captionBold: ['14px', { lineHeight: '20px' }],
- captionSm: ['12px', { lineHeight: '14px' }],
- captionSmBold: ['12px', { lineHeight: '14px' }],
- captionXs: ['10px', { lineHeight: '14px' }],
- captionXsBold: ['10px', { lineHeight: '14px' }],
- captionDropdownDefault: ['13px', { lineHeight: '20px' }],
- sidebarDefault: ['14px', { lineHeight: '20px' }],
- sidebarSelected: ['14px', { lineHeight: '20px' }],
},
fontWeight: {
/**