@studiocms/ui 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiocms/ui",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "The UI library for StudioCMS. Includes the layouts & components we use to build StudioCMS.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,7 +21,8 @@
21
21
  "astro-ui-library",
22
22
  "astro-components",
23
23
  "studiocms",
24
- "ui-library"
24
+ "ui-library",
25
+ "astro-integration"
25
26
  ],
26
27
  "homepage": "https://ui.studiocms.dev",
27
28
  "publishConfig": {
@@ -42,8 +43,9 @@
42
43
  "./types": "./src/types/index.ts"
43
44
  },
44
45
  "dependencies": {
46
+ "@iconify-json/heroicons": "^1.2.1",
45
47
  "@iconify/utils": "^2.1.33",
46
- "@iconify-json/heroicons": "^1.2.1"
48
+ "pathe": "^1.1.2"
47
49
  },
48
50
  "peerDependencies": {
49
51
  "astro": "^4.5 || ^5.0.0-beta.0"
@@ -9,11 +9,16 @@ interface Props {
9
9
  background?: 'background-base' | 'background-step-1' | 'background-step-2' | 'background-step-3';
10
10
  }
11
11
 
12
+ const hasDefaultSlot = Astro.slots.has('default');
13
+
12
14
  const { background = 'background-base' } = Astro.props;
13
15
  ---
14
16
  <div class="sui-divider-container">
15
17
  <hr class="sui-divider-line" />
16
- <div class="sui-divider-content" style={`background-color: hsl(var(--${background}));`}>
18
+ <div
19
+ class="sui-divider-content"
20
+ style={`background-color: hsl(var(--${background})); padding: ${hasDefaultSlot ? '.25rem .5rem;' : '0'}`}
21
+ >
17
22
  <slot />
18
23
  </div>
19
24
  </div>
@@ -28,9 +33,8 @@ const { background = 'background-base' } = Astro.props;
28
33
 
29
34
  .sui-divider-line {
30
35
  position: absolute;
31
- top: 50%;
32
36
  left: 50%;
33
- transform: translate(-50%, -50%);
37
+ transform: translate(-50%, 0);
34
38
  width: 100%;
35
39
  height: 1px;
36
40
  background-color: hsl(var(--border));
@@ -39,7 +43,6 @@ const { background = 'background-base' } = Astro.props;
39
43
  }
40
44
 
41
45
  .sui-divider-content {
42
- padding: .25rem .5rem;
43
46
  z-index: 2;
44
47
  color: hsl(var(--text-muted));
45
48
  }
@@ -30,7 +30,6 @@ const { icon, label, color = 'primary' } = Astro.props;
30
30
  data-label={label}
31
31
  data-color={color}
32
32
  data-tab-id={id}
33
- class=""
34
33
  >
35
34
  <slot />
36
35
  </sui-tab-item>
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import { AstroError } from 'astro/errors';
2
3
  import { Icon } from '../../utils';
3
4
  import type { StudioCMSColorway } from '../../utils/colors';
4
5
  import { generateID } from '../../utils/generateID';
@@ -77,8 +78,21 @@ const markTabAsActive = (tabId: string, html: string): string => {
77
78
  if (!tabId) return html;
78
79
 
79
80
  const updatedHtml = html.replace(
80
- new RegExp(`(<sui-tab-item[^>]*data-tab-id="${tabId}"[^>]*class=")([^"]*)(")`, 'g'),
81
- '$1$2 active$3'
81
+ /<sui-tab-item[^>]*data-tab-id="([^"]*)"[^>]*>/g,
82
+ (match, tabIdValue) => {
83
+ // Check if the tabId matches
84
+ if (tabIdValue === tabId) {
85
+ // Check if the element already has a class attribute
86
+ if (match.includes('class="')) {
87
+ // If class attribute exists, add 'active' to the class attribute
88
+ return match.replace(/(class="[^"]*)"/, '$1 active"');
89
+ }
90
+
91
+ // If class attribute does not exist, add it
92
+ return match.replace(/(<sui-tab-item[^>]*data-tab-id="[^"]*")/, '$1 class="active"');
93
+ }
94
+ return match; // Return original if the tabId does not match
95
+ }
82
96
  );
83
97
 
84
98
  return updatedHtml;
@@ -288,6 +302,9 @@ const containerId = generateID('sui-tabs-container');
288
302
  font-size: 0.875em;
289
303
  outline: 2px solid transparent;
290
304
  outline-offset: 2px;
305
+ display: flex;
306
+ align-items: center;
307
+ justify-content: center;
291
308
  }
292
309
 
293
310
  .sui-tab-header * {
@@ -1,5 +1,6 @@
1
1
  import type { AstroIntegration } from 'astro';
2
2
  import { createResolver } from './utils/create-resolver';
3
+ import { viteVirtualModulePluginBuilder } from './utils/virtual-module-plugin-builder';
3
4
 
4
5
  // biome-ignore lint/complexity/noBannedTypes: Will be implemented in v0.3.0
5
6
  type Options = {};
@@ -7,11 +8,23 @@ type Options = {};
7
8
  export default function integration(options: Options = {}): AstroIntegration {
8
9
  const { resolve } = createResolver(import.meta.url);
9
10
 
11
+ const globalCss = viteVirtualModulePluginBuilder(
12
+ 'studiocms:ui/global-css',
13
+ 'sui-global-css',
14
+ `import '${resolve('./css/global.css')}'`
15
+ );
16
+
10
17
  return {
11
18
  name: '@studiocms/ui',
12
19
  hooks: {
13
- 'astro:config:setup': ({ injectScript }) => {
14
- injectScript('page-ssr', `import '${resolve('./css/global.css')}'`);
20
+ 'astro:config:setup': ({ injectScript, updateConfig }) => {
21
+ updateConfig({
22
+ vite: {
23
+ plugins: [globalCss()],
24
+ },
25
+ });
26
+
27
+ injectScript('page-ssr', `import 'studiocms:ui/global-css';`);
15
28
  },
16
29
  },
17
30
  };
@@ -1,5 +1,5 @@
1
- import { dirname, resolve } from 'node:path'; // Swapped out pathe for node:path to cut down on dependencies
2
1
  import { fileURLToPath } from 'node:url';
2
+ import { dirname, resolve } from 'pathe';
3
3
 
4
4
  /**
5
5
  * From the Astro Integration Kit (https://astro-integration-kit.netlify.app/).
@@ -0,0 +1,37 @@
1
+ import type { AstroConfig } from 'astro';
2
+
3
+ type VitePlugin = Required<AstroConfig['vite']>['plugins'][number];
4
+
5
+ /**
6
+ * Builds a Vite plugin that creates a virtual module.
7
+ *
8
+ * @param moduleId - The ID of the virtual module.
9
+ * @param name - The name of the plugin.
10
+ * @param moduleContent - The content of the virtual module.
11
+ * @returns A Vite plugin that resolves and loads the virtual module.
12
+ */
13
+ export function viteVirtualModulePluginBuilder(
14
+ moduleId: string,
15
+ name: string,
16
+ moduleContent: string
17
+ ) {
18
+ return function modulePlugin(): VitePlugin {
19
+ const resolvedVirtualModuleId = `\0${moduleId}`; // Prefix with \0 to avoid conflicts
20
+
21
+ return {
22
+ name,
23
+ resolveId(id) {
24
+ if (id === moduleId) {
25
+ return resolvedVirtualModuleId;
26
+ }
27
+ return;
28
+ },
29
+ load(id) {
30
+ if (id === resolvedVirtualModuleId) {
31
+ return moduleContent;
32
+ }
33
+ return;
34
+ },
35
+ };
36
+ };
37
+ }