Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoprefix the file-selector-button pseudo-element #1412

Merged
merged 3 commits into from
Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 52 additions & 0 deletions data/prefixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,47 @@ function f(data, opts, callback) {
callback(need.sort(browsersSort))
}

// Convert MDN data
function f2(data, opts, callback) {
data = data.__compat

if (!callback) {
;[callback, opts] = [opts, {}]
}

let need = []

for (let browser in data.support) {
let versions = data.support[browser]

if (Array.isArray(versions)) {
versions = versions[0]
}

let versionAdded = versions.version_added

if (versionAdded) {
if (browser === 'samsunginternet_android') {
browser = 'samsung'
} else if (browser === 'safari_ios') {
browser = 'ios_saf'
} else if (browser === 'opera_android') {
browser = 'op_mob'
} else if (browser === 'chrome_android') {
browser = 'and_chr'
} else if (browser === 'firefox_android') {
browser = 'and_ff'
} else if (browser === 'webview_android') {
browser = 'android'
}

need.push(browser + ' ' + versionAdded)
}
}

callback(need.sort(browsersSort))
}

// Add data for all properties
let result = {}

Expand Down Expand Up @@ -521,6 +562,17 @@ f(prefixFullscreen, { match: /x(\s#2|$)/ }, browsers =>
})
)

// File selector button
const bcd = require('@mdn/browser-compat-data')

f2(bcd.css.selectors['file-selector-button'], browsers =>
prefix(['::file-selector-button'], {
selector: true,
feature: 'fullscreen',
browsers
})
)

// Tab size
let prefixTabsize = require('caniuse-lite/data/features/css3-tabsize')

Expand Down
17 changes: 17 additions & 0 deletions lib/hacks/file-selector-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let Selector = require('../selector')

class FileSelectorButton extends Selector {
/**
* Return different selectors depend on prefix
*/
prefixed(prefix) {
if (prefix === '-webkit-') {
return '::-webkit-file-upload-button'
}
return `::file-selector-button`
}
}

FileSelectorButton.names = ['::file-selector-button']

module.exports = FileSelectorButton
2 changes: 2 additions & 0 deletions lib/prefixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let utils = require('./utils')
let hackFullscreen = require('./hacks/fullscreen')
let hackPlaceholder = require('./hacks/placeholder')
let hackPlaceholderShown = require('./hacks/placeholder-shown')
let hackFileSelectorButton = require('./hacks/file-selector-button')
let hackFlex = require('./hacks/flex')
let hackOrder = require('./hacks/order')
let hackFilter = require('./hacks/filter')
Expand Down Expand Up @@ -68,6 +69,7 @@ let hackFilterValue = require('./hacks/filter-value')
Selector.hack(hackFullscreen)
Selector.hack(hackPlaceholder)
Selector.hack(hackPlaceholderShown)
Selector.hack(hackFileSelectorButton)
Declaration.hack(hackFlex)
Declaration.hack(hackOrder)
Declaration.hack(hackFilter)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"postcss": "^8.1.0"
},
"dependencies": {
"@mdn/browser-compat-data": "^3.3.10",
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
"browserslist": "^4.16.6",
"caniuse-lite": "^1.0.30001230",
"colorette": "^1.2.2",
Expand Down
5 changes: 5 additions & 0 deletions test/autoprefixer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ let ffgradienter = autoprefixer({
let selectorer = autoprefixer({
overrideBrowserslist: ['Chrome 25', 'Firefox > 17', 'IE 10', 'Edge 12']
})
let fileSelectorButtoner = autoprefixer({
overrideBrowserslist: ['Chrome > 25', 'Firefox > 85']
})
let placeholderShowner = autoprefixer({
overrideBrowserslist: ['IE >= 10']
})
Expand Down Expand Up @@ -123,6 +126,8 @@ function prefixer(name: string): Plugin {
return intrinsicer
} else if (name === 'selectors' || name === 'placeholder') {
return selectorer
} else if (name === 'selectors' || name === 'file-selector-button') {
return fileSelectorButtoner
} else if (name === 'placeholder-shown') {
return placeholderShowner
} else if (name === 'backdrop-filter' || name === 'overscroll-behavior') {
Expand Down
3 changes: 3 additions & 0 deletions test/cases/file-selector-button.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::file-selector-button {
ai marked this conversation as resolved.
Show resolved Hide resolved
background: black
}
7 changes: 7 additions & 0 deletions test/cases/file-selector-button.out.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
::-webkit-file-upload-button {
background: black
}

::file-selector-button {
background: black
}
1,854 changes: 932 additions & 922 deletions yarn.lock

Large diffs are not rendered by default.