Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
run: |
echo "🔨 Generating UI assets..."
npm install
npm run lint
npm run build
cp ./build/injectNav.iife.js ../quantinuum_sphinx/static/injectNav.iife.js
cp ./build/syncTheme.iife.js ../quantinuum_sphinx/static/syncTheme.iife.js
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ jobs:
run: |
echo "🔨 Generating UI assets..."
npm install
npm run lint
npm run build
cp ./build/injectNav.iife.js ../quantinuum_sphinx/static/injectNav.iife.js
cp ./build/syncTheme.iife.js ../quantinuum_sphinx/static/syncTheme.iife.js
Expand Down
10 changes: 0 additions & 10 deletions sphinx-ui/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sphinx-ui/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"build": "npx tsdown",
"lint": "tsc --noEmit",
"format": "prettier --write --config='../../libraries/ui/.prettierrc' --ignore-path='.prettierignore' ."
},
"author": "",
Expand All @@ -23,7 +24,6 @@
"prettier-plugin-tailwindcss": "^0.6.6",
"serve": "^14.2.3",
"tailwindcss": "^3.4.4",
"tsc": "^2.0.4",
"tsdown": "^0.21.7",
"typescript": "^6.0.3"
},
Expand Down
23 changes: 22 additions & 1 deletion sphinx-ui/react/postcss.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,34 @@ import autoprefixer from 'autoprefixer'
import prefixSelector from 'postcss-prefix-selector'
import failOnWarn from 'postcss-fail-on-warn'

const tailwindScopeSelector = '.use-tailwind'

function scopeTailwindSelector(prefix, selector, prefixedSelector) {
if (selector === '*') {
return `${prefix}, ${prefixedSelector}`
}

if (selector.startsWith('::')) {
return `${prefix}${selector}, ${prefixedSelector}`
}

if (selector.startsWith('.')) {
return `${prefixedSelector}, ${prefix}${selector}`
}

return prefixedSelector
}

export default {
plugins: [
postcssImport,
tailwindcssNesting,
tailwindcss,
autoprefixer,
prefixSelector({ prefix: '.use-tailwind' }),
prefixSelector({
prefix: tailwindScopeSelector,
transform: scopeTailwindSelector,
}),
failOnWarn,
],
}
45 changes: 43 additions & 2 deletions sphinx-ui/react/src/injectNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,53 @@ const GA_ID = __NEXT_PUBLIC_GA_ID__;

const tailwindScopeClassName = 'use-tailwind';

(() => {
document.body.classList.add(tailwindScopeClassName)
const isTailwindDialogPortalElement = (element: Element): element is HTMLElement => {
if (!(element instanceof HTMLElement)) return false

const { classList } = element
return (
classList.contains('fixed') &&
classList.contains('z-50') &&
(classList.contains('inset-0') || element.getAttribute('role') === 'dialog')
)
}

const scopeTailwindDialogPortalElements = (root: ParentNode = document.body) => {
const scopeElement = (element: Element) => {
if (isTailwindDialogPortalElement(element)) {
element.classList.add(tailwindScopeClassName)
}
}

if (root instanceof Element) {
scopeElement(root)
}

root.querySelectorAll('[class][data-state], [class][role="dialog"]').forEach(scopeElement)
}

const observeTailwindDialogPortalElements = () => {
scopeTailwindDialogPortalElements()

const observer = new MutationObserver((records) => {
records.forEach((record) => {
record.addedNodes.forEach((node) => {
if (node instanceof Element) {
scopeTailwindDialogPortalElements(node)
}
})
})
})

observer.observe(document.body, { childList: true, subtree: true })
}

(() => {
const mountElement = document.querySelector('.nexus-nav')
if (!mountElement) return

observeTailwindDialogPortalElements()

const renderIn = document.createElement('div')
mountElement.appendChild(renderIn)

Expand Down
2 changes: 2 additions & 0 deletions sphinx-ui/react/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="node" />

import path from 'path'
import { Config } from 'tailwindcss'
import plugin from 'tailwindcss/plugin'
Expand Down
4 changes: 3 additions & 1 deletion sphinx-ui/react/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// <reference types="node" />

import { defineConfig } from 'tsdown'

const NEXT_PUBLIC_GA_ID = JSON.stringify(process.env.NEXT_PUBLIC_GA_ID || '')
const NEXT_PUBLIC_GA_ID = JSON.stringify(process.env['NEXT_PUBLIC_GA_ID'] || '')

export default defineConfig([
// Script for injecting nav into sphinx build.
Expand Down
25 changes: 0 additions & 25 deletions sphinx-ui/react/tsup.config.ts

This file was deleted.

30 changes: 15 additions & 15 deletions sphinx-ui/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.