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

Add custom and accessible outlines #162

Merged
merged 2 commits into from
Oct 17, 2020
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
2 changes: 2 additions & 0 deletions __fixtures__/interactivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ tw`cursor-not-allowed`

// https://tailwindcss.com/docs/outline
tw`outline-none`
tw`outline-white`
tw`outline-black`

// https://tailwindcss.com/docs/pointer-events
tw`pointer-events-none`
Expand Down
13 changes: 12 additions & 1 deletion __snapshots__/plugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7434,6 +7434,8 @@ tw\`cursor-not-allowed\`

// https://tailwindcss.com/docs/outline
tw\`outline-none\`
tw\`outline-white\`
tw\`outline-black\`

// https://tailwindcss.com/docs/pointer-events
tw\`pointer-events-none\`
Expand Down Expand Up @@ -7481,7 +7483,16 @@ tw\`select-auto\`
}) // https://tailwindcss.com/docs/outline

;({
outline: 0,
outline: '2px solid transparent',
outlineOffset: '2px',
})
;({
outline: '2px dotted white',
outlineOffset: '2px',
})
;({
outline: '2px dotted black',
outlineOffset: '2px',
}) // https://tailwindcss.com/docs/pointer-events

;({
Expand Down
12 changes: 6 additions & 6 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"dset": "^2.0.1",
"lodash.merge": "^4.6.2",
"string-similarity": "^4.0.1",
"tailwindcss": "^1.8.8",
"tailwindcss": "^1.9.1",
"timsort": "^0.3.0"
},
"peerDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/config/dynamicStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ export default {
cursor: { prop: 'cursor', config: 'cursor' },

// https://tailwindcss.com/docs/outline
outline: { plugin: 'outline' },

// https://tailwindcss.com/docs/pointer-events
// https://tailwindcss.com/docs/resize
// https://tailwindcss.com/docs/user-select
Expand Down
4 changes: 1 addition & 3 deletions src/config/staticStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,8 @@ export default {
'appearance-none': { output: { appearance: 'none' } },

// https://tailwindcss.com/docs/cursor
// See dynamicStyles.js

// https://tailwindcss.com/docs/outline
'outline-none': { output: { outline: 0 } },
// See dynamicStyles.js

// https://tailwindcss.com/docs/pointer-events
'pointer-events-none': {
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export { default as animation } from './animation'
export { default as placeholder } from './placeholder'
export { default as container } from './container'
export { default as gradient } from './gradient'
export { default as bg } from './bg'
export { default as border } from './border'
export { default as container } from './container'
export { default as divide } from './divide'
export { default as gradient } from './gradient'
export { default as outline } from './outline'
export { default as placeholder } from './placeholder'
export { default as space } from './space'
export { default as text } from './text'
export { default as bg } from './bg'
24 changes: 24 additions & 0 deletions src/plugins/outline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default properties => {
const {
theme,
match,
getConfigValue,
errors: { errorSuggestions },
pieces: { important },
} = properties

const classValue = match(/(?<=(outline)-)([^]*)/)
const configValue = config => getConfigValue(theme(config), classValue)

const value = configValue('outline')
if (!value) {
errorSuggestions({ config: ['outline'] })
}

const [outline, outlineOffset = 0] = Array.isArray(value) ? value : [value]

return {
outline: `${outline}${important}`,
...(outlineOffset && { outlineOffset: `${outlineOffset}${important}` }),
}
}
15 changes: 12 additions & 3 deletions src/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@ const getCustomSuggestions = className => {
const flattenObject = (object, prefix = '') =>
Object.keys(object).reduce((result, k) => {
const pre = prefix.length > 0 ? prefix + '-' : ''
if (typeof object[k] === 'object')
Object.assign(result, flattenObject(object[k], pre + k))
else result[pre + k] = object[k]

const value = object[k]
const fullKey = pre + k

if (Array.isArray(value)) {
result[fullKey] = value
} else if (typeof value !== 'object') {
Object.assign(result, flattenObject(value, fullKey))
} else {
result[fullKey] = value
}

return result
}, {})

Expand Down