Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/mux-input-vanilla-extract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sanity-plugin-mux-input": patch
---

Migrate styling from styled-components to vanilla-extract (zero-runtime CSS)
22 changes: 19 additions & 3 deletions plugins/sanity-plugin-mux-input/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,25 @@
"types": "./dist/index.d.ts",
"exports": {
".": "./src/_exports/index.ts",
"./bundle.css": {
"types": "./dist/bundle-css.d.ts",
"browser": "./dist/bundle.css",
"style": "./dist/bundle.css",
"node": "./dist/bundle-css.js",
"default": "./dist/bundle-css.js"
},
"./package.json": "./package.json"
},
"publishConfig": {
"exports": {
".": "./dist/index.js",
"./bundle.css": {
"types": "./dist/bundle-css.d.ts",
"browser": "./dist/bundle.css",
"style": "./dist/bundle.css",
"node": "./dist/bundle-css.js",
"default": "./dist/bundle-css.js"
},
"./package.json": "./package.json"
}
},
Expand All @@ -48,6 +62,8 @@
"@sanity/icons": "catalog:",
"@sanity/ui": "catalog:",
"@sanity/uuid": "catalog:",
"@vanilla-extract/dynamic": "catalog:",
"clsx": "^2.1.1",
"iso-639-1": "^3.1.6",
"jsonwebtoken-esm": "^1.0.5",
"lodash": "^4.18.1",
Expand All @@ -65,21 +81,21 @@
"@sanity/client": "catalog:",
"@sanity/tsconfig": "catalog:",
"@sanity/tsdown-config": "catalog:",
"@sanity/vanilla-extract-vite-plugin": "catalog:",
"@types/lodash": "^4.17.24",
"@types/node": "catalog:",
"@types/react": "catalog:",
"@types/react-is": "catalog:",
"@vanilla-extract/css": "catalog:",
"babel-plugin-react-compiler": "catalog:",
"react": "catalog:",
"react-dom": "catalog:",
"sanity": "catalog:",
"styled-components": "catalog:",
"tsdown": "catalog:"
},
"peerDependencies": {
"react": "catalog:peer",
"sanity": "catalog:peer",
"styled-components": "catalog:peer"
"sanity": "catalog:peer"
},
"engines": {
"node": ">=20.19 <22 || >=22.12"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {style} from '@vanilla-extract/css'

export const logo = style({
display: 'inline-block',
height: '0.8em',
marginRight: '1em',
transform: 'translate(0.3em, -0.2em)',
})
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import {styled} from 'styled-components'

import MuxLogo from './MuxLogo'

const Logo = styled.span`
display: inline-block;
height: 0.8em;
margin-right: 1em;
transform: translate(0.3em, -0.2em);
`
import {logo} from './ConfigureApi.css'

export const Header = () => (
<>
<Logo>
<span className={logo}>
<MuxLogo height={13} />
</Logo>
</span>
API Credentials
</>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {globalStyle, style} from '@vanilla-extract/css'

export const rangeInput = style({
width: '100%',
height: 4,
borderRadius: 2,
background: 'var(--card-border-color)',
outline: 'none',
WebkitAppearance: 'none',
appearance: 'none',
selectors: {
'&::-webkit-slider-thumb': {
WebkitAppearance: 'none',
appearance: 'none',
width: 16,
height: 16,
borderRadius: '50%',
background: 'var(--card-focus-ring-color, #2276fc)',
cursor: 'pointer',
border: '2px solid white',
boxShadow: '0 1px 3px rgba(0, 0, 0, 0.2)',
},
'&::-moz-range-thumb': {
width: 16,
height: 16,
borderRadius: '50%',
background: 'var(--card-focus-ring-color, #2276fc)',
cursor: 'pointer',
border: '2px solid white',
boxShadow: '0 1px 3px rgba(0, 0, 0, 0.2)',
},
'&:hover::-webkit-slider-thumb': {
background: 'var(--card-focus-ring-color, #1a5fc7)',
},
'&:hover::-moz-range-thumb': {
background: 'var(--card-focus-ring-color, #1a5fc7)',
},
},
})

export const watermarkOverlay = style({
position: 'absolute',
maxWidth: 200,
cursor: 'move',
userSelect: 'none',
zIndex: 10,
pointerEvents: 'auto',
selectors: {
'&:hover': {
outline: '2px dashed rgba(255, 255, 255, 0.8)',
outlineOffset: 4,
},
},
})

globalStyle(`${watermarkOverlay} img`, {
width: '100%',
height: 'auto',
display: 'block',
pointerEvents: 'none',
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,11 @@ import {CheckmarkCircleIcon} from '@sanity/icons/CheckmarkCircle'
import {ErrorOutlineIcon} from '@sanity/icons/ErrorOutline'
import {Box, Button, Card, Flex, Grid, Stack, Text, TextInput} from '@sanity/ui'
import {useCallback, useEffect, useRef, useState} from 'react'
import {styled} from 'styled-components'

import {convertWatermarkToMuxOverlay} from '../util/convertWatermarkToMux'
import type {MuxOverlaySettings, WatermarkConfig} from '../util/types'

const RangeInput = styled.input`
width: 100%;
height: 4px;
border-radius: 2px;
background: var(--card-border-color);
outline: none;
-webkit-appearance: none;
appearance: none;

&::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 16px;
height: 16px;
border-radius: 50%;
background: var(--card-focus-ring-color, #2276fc);
cursor: pointer;
border: 2px solid white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

&::-moz-range-thumb {
width: 16px;
height: 16px;
border-radius: 50%;
background: var(--card-focus-ring-color, #2276fc);
cursor: pointer;
border: 2px solid white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

&:hover::-webkit-slider-thumb {
background: var(--card-focus-ring-color, #1a5fc7);
}

&:hover::-moz-range-thumb {
background: var(--card-focus-ring-color, #1a5fc7);
}
`

const WatermarkOverlay = styled.div<{$opacity: number}>`
position: absolute;
max-width: 200px;
opacity: ${(props) => props.$opacity};
cursor: move;
user-select: none;
z-index: 10;
pointer-events: auto;

img {
width: 100%;
height: auto;
display: block;
pointer-events: none;
}

&:hover {
outline: 2px dashed rgba(255, 255, 255, 0.8);
outline-offset: 4px;
}
`
import {rangeInput, watermarkOverlay} from './DraggableWatermark.css'

interface DraggableWatermarkProps {
watermark: WatermarkConfig
Expand Down Expand Up @@ -335,15 +274,16 @@ export default function DraggableWatermark({
}

return (
<WatermarkOverlay
// oxlint-disable-next-line jsx-a11y/no-static-element-interactions
<div
ref={watermarkRef}
$opacity={opacityForRender}
className={watermarkOverlay}
onMouseDown={hasManualOverlay ? undefined : handleMouseDown}
// oxlint-disable-next-line react/react-compiler
style={computeWatermarkStyle()}
style={{...computeWatermarkStyle(), opacity: opacityForRender}}
>
<img src={watermark.imageUrl} alt="Watermark" draggable={false} />
</WatermarkOverlay>
</div>
)
}

Expand Down Expand Up @@ -816,7 +756,8 @@ export function WatermarkControls({
return `Size: ${px}px`
})()}
</Text>
<RangeInput
<input
className={rangeInput}
type="range"
// oxlint-disable-next-line react/react-compiler
value={(() => {
Expand Down Expand Up @@ -855,7 +796,8 @@ export function WatermarkControls({
<Text size={1} weight="medium">
Opacity: {Math.round((watermark.opacity ?? 0.7) * 100)}%
</Text>
<RangeInput
<input
className={rangeInput}
type="range"
value={watermark.opacity ?? 0.7}
min={0}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {style} from '@vanilla-extract/css'

export const hiddenInput = style({
overflow: 'hidden',
width: '0.1px',
height: '0.1px',
opacity: 0,
position: 'absolute',
zIndex: -1,
})

export const label = style({
position: 'relative',
})
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import {Button, type ButtonProps} from '@sanity/ui'
import {useCallback, useId, useRef} from 'react'
import {styled} from 'styled-components'

const HiddenInput = styled.input`
overflow: hidden;
width: 0.1px;
height: 0.1px;
opacity: 0;
position: absolute;
z-index: -1;
`

const Label = styled.label`
position: relative;
`
import {hiddenInput, label} from './FileInputButton.css'

export interface FileInputButtonProps extends Omit<ButtonProps, 'onSelect'> {
onSelect: (files: FileList) => void
Expand All @@ -32,8 +20,9 @@ export const FileInputButton = ({onSelect, accept, ...props}: FileInputButtonPro
)
const handleButtonClick = useCallback(() => inputRef.current?.click(), [])
return (
<Label htmlFor={inputId}>
<HiddenInput
<label className={label} htmlFor={inputId}>
<input
className={hiddenInput}
accept={accept}
ref={inputRef}
tabIndex={0}
Expand All @@ -49,6 +38,6 @@ export const FileInputButton = ({onSelect, accept, ...props}: FileInputButtonPro
style={{width: '100%'}}
{...props}
/>
</Label>
</label>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {createVar, globalStyle, style} from '@vanilla-extract/css'

export const boxShadowFocusVar = createVar()

export const fileButton = style({
position: 'relative',
selectors: {
'&:not([data-disabled="true"]):focus-within': {
boxShadow: boxShadowFocusVar,
},
},
})

globalStyle(`${fileButton} input`, {
overflow: 'hidden',
top: 0,
left: 0,
width: '100%',
height: '100%',
position: 'absolute',
minWidth: 0,
display: 'block',
appearance: 'none',
padding: 0,
margin: 0,
border: 0,
opacity: 0,
})
Loading
Loading