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 support for multiple font-face rules #3

Merged
merged 6 commits into from
Mar 4, 2018
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
33 changes: 13 additions & 20 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 @@ -37,7 +37,7 @@
"@types/mocha": "^2.2.43",
"@types/node": "^8.0.34",
"chai": "^4.1.2",
"jss": "^9.0.0",
"jss": "^9.8.0",
"mocha": "^4.0.1",
"rimraf": "^2.6.2",
"ts-loader": "^2.3.7",
Expand Down
60 changes: 52 additions & 8 deletions src/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('jss-rtl', () => {

it('should generate correct CSS', () => {
expect(sheet.toString()).to.be.equals([
'.a-0-1 {',
'.a-0-2-1 {',
' padding-right: 1px;',
'}',
].join('\n'));
Expand All @@ -50,7 +50,7 @@ describe('jss-rtl', () => {

it('should generate unchanged CSS', () => {
expect(sheet.toString()).to.be.equals([
'.a-0-1 {',
'.a-0-6-1 {',
' padding-left: 1px;',
'}',
].join('\n'));
Expand All @@ -59,7 +59,7 @@ describe('jss-rtl', () => {
it('should remove the flip property from the style even when disabled', () => {
sheet = jss.createStyleSheet({ a: { flip: true, 'padding-left': '1px' } });
expect(sheet.toString()).to.be.equals([
'.a-0-2 {',
'.a-0-8-2 {',
' padding-left: 1px;',
'}',
].join('\n'));
Expand All @@ -80,7 +80,7 @@ describe('jss-rtl', () => {

it('should generate unchanged CSS', () => {
expect(sheet.toString()).to.be.equals([
'.a-0-1 {',
'.a-0-10-1 {',
' padding-left: 1px;',
'}',
].join('\n'));
Expand All @@ -105,10 +105,10 @@ describe('jss-rtl', () => {

it('should generate unchanged CSS and remove the flip prop', () => {
expect(sheet.toString()).to.be.equals([
'.a-0-1 {',
'.a-0-12-1 {',
' padding-right: 1px;',
'}',
'.b-0-2 {',
'.b-0-12-2 {',
' padding-left: 1px;',
'}',
].join('\n'));
Expand All @@ -134,15 +134,59 @@ describe('jss-rtl', () => {

it('should generate changed CSS and remove the flip prop', () => {
expect(sheet.toString()).to.be.equals([
'.a-0-1 {',
'.a-0-16-1 {',
' padding-left: 1px;',
'}',
'.b-0-2 {',
'.b-0-16-2 {',
' padding-right: 1px;',
'}',
].join('\n'));
});
});

describe('font-face rule', () => {
let sheet: any;

beforeEach(() => {
jss = create().use(rtl());
sheet = jss.createStyleSheet({
'@font-face': [
{
'font-family': 'Roboto',
'font-style': 'normal',
'font-wieght': 'normal',
src: 'url(/fonts/Roboto.woff2) format("woff2")',
},
{
'font-family': 'Roboto',
'font-style': 'normal',
'font-wieght': 300,
src: 'url(/fonts/Roboto-Light.woff2) format("woff2")',
},
],
});
});

it('should add rules', () => {
expect(sheet.getRule('@font-face')).to.be.ok;
});

it('should generate multiple font-face rules', () => {
expect(sheet.toString()).to.be.equals([
'@font-face {',
' font-family: Roboto;',
' font-style: normal;',
' font-wieght: normal;',
' src: url(/fonts/Roboto.woff2) format("woff2");',
'}',
'@font-face {',
' font-family: Roboto;',
' font-style: normal;',
' font-wieght: 300;',
' src: url(/fonts/Roboto-Light.woff2) format("woff2");',
'}',
].join('\n'));
});
});

});
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export interface JssRTLOptions {

export default function jssRTL({ enabled = true, opt = 'out' }: JssRTLOptions = {}) {
return {
onProcessStyle(style: any, _: any, sheet: any) {
onProcessStyle(style: any, rule: any, sheet: any) {
if (rule.type === 'font-face') {
return style;
}

if (!enabled) {
if (typeof style.flip === 'boolean') {
delete style.flip;
Expand Down