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

Prefixed token issue #5

Closed
Closed
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
"@dash-ui/styles": "<rootDir>/src/index.ts"
},
"testMatch": [
"<rootDir>/{server/src,src}/**/?(*.)test.ts"
"<rootDir>/src/**/*(*.)@(spec|test).[jt]s?(x)",
"<rootDir>/server/src/**/*(*.)@(spec|test).[jt]s?(x)"
],
"collectCoverageFrom": [
"**/src/**/*.ts"
Expand Down
3 changes: 2 additions & 1 deletion src/create-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,9 @@ function serializeTokens(
vars[key] = result.vars
css += result.css
} else {
const allowedKey = key.replace(/^[^\w-]+/g, '')
let name = cssCase(
names.length > 0 ? names.join('-') + '-' + key : key
names.length > 0 ? names.join('-') + '-' + allowedKey : allowedKey
).replace(cssDisallowedRe, '-')
vars[key] =
'var(' +
Expand Down
25 changes: 25 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,31 @@ describe('createStyles()', () => {
expect(style.css('primary')).toEqual('color:var(--color-primary);')
expect(myStyles.theme('light')).toEqual('ui-light-theme')
})

it('should remove special character(s) from the start of the token key.', () => {
const myStyles = createStyles({
tokens: {
space: {
$1: '5px',
$2: '10px',
},
color: {
red: {$100: 'red'},
},
},
})

const style = myStyles({
primary: ({space, color}) => ({
paddingLeft: space.$2,
color: color.red.$100,
}),
})

expect(style.css('primary')).toEqual(
'padding-left:var(--space-2);color:var(--color-red-100);'
)
})
})

describe('styles()', () => {
Expand Down
14 changes: 8 additions & 6 deletions test/resolve-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ const snapshots = '__snapshots__'
module.exports = {
resolveSnapshotPath: (testPath, snapshotExtension) =>
path.join(
testPath.split('/').slice(0, -1).join('/'),
snapshots,
testPath.split('/').pop() + snapshotExtension
path.join(path.dirname(testPath), snapshots),
path.basename(testPath) + snapshotExtension
),

resolveTestPath: (snapshotFilePath, snapshotExtension) =>
path.join(
snapshotFilePath.split('/').slice(0, -2).join('/'),
snapshotFilePath.split('/').pop().slice(0, -snapshotExtension.length)
path.dirname(snapshotFilePath),
'..',
path.basename(snapshotFilePath, snapshotExtension)
),
testPathForConsistencyCheck: 'src/foo.test.js',

testPathForConsistencyCheck: path.join('src', 'foo.test.js'),
}