Skip to content

Commit

Permalink
Merge branch 'master' into col-bot-marg
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblack authored Jan 10, 2020
2 parents a53cc40 + 472bb65 commit 7145b82
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 56 deletions.
25 changes: 14 additions & 11 deletions packages/bundler/src/commands/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const fs = require('fs-extra');
const klaw = require('klaw-sync');
const os = require('os');
const path = require('path');
const isWin = process.platform === 'win32';
const replace = require('replace-in-file');
const { reporter } = require('@carbon/cli-reporter');

const tmpDir = os.tmpdir();

Expand All @@ -24,12 +26,14 @@ async function inline(options, info) {

await Promise.all([fs.remove(inlineFolder), fs.remove(vendorFolder)]);

reporter.info('Inlining sass dependencies');
await inlineSassDependencies(
packageJsonPath,
sourceFolder,
vendorFolder,
cwd
);
reporter.success('Done');
}

async function inlineSassDependencies(
Expand All @@ -50,8 +54,9 @@ async function inlineSassDependencies(
];
const inlinedDependencies = (await Promise.all(
allPossibleDependencies.map(async dependency => {
const [packageFolder, scssFolder] = await findSassModule(dependency, cwd);
if (packageFolder) {
const modules = await findSassModule(dependency, cwd);
if (modules) {
const [scssFolder] = modules;
const dependencyOutputFolder = path.join(vendorFolder, dependency);

await fs.copy(scssFolder, dependencyOutputFolder);
Expand Down Expand Up @@ -84,11 +89,7 @@ async function inlineSassDependencies(
return false;
}

if (path.basename(src) === 'index.scss') {
return false;
}

return true;
return path.basename(src) !== 'index.scss';
},
});
await fs.copy(tmpFolder, inlineFolder);
Expand All @@ -113,7 +114,9 @@ async function inlineSassDependencies(
files: file.path,
from: REPLACE_REGEX,
to(_, match) {
return `@import '${relativeImportPath}/${match}`;
return `@import '${
isWin ? relativeImportPath.replace('\\', '/') : relativeImportPath
}/${match}`;
},
});
})
Expand All @@ -123,20 +126,20 @@ async function inlineSassDependencies(
function findSassModule(packageName, cwd) {
let currentDirectory = cwd;

while (currentDirectory !== '/') {
while (currentDirectory !== path.dirname(currentDirectory)) {
const nodeModulesFolder = path.join(currentDirectory, 'node_modules');
const packageFolder = path.join(nodeModulesFolder, packageName);
const scssFolder = path.join(packageFolder, 'scss');
const packageJsonPath = path.join(packageFolder, 'package.json');

if (fs.existsSync(scssFolder)) {
return [packageFolder, scssFolder, packageJsonPath];
return [scssFolder, packageFolder, packageJsonPath];
}

currentDirectory = path.dirname(currentDirectory);
}

return [false];
return false;
}

module.exports = inline;
38 changes: 26 additions & 12 deletions packages/components/docs/sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -7614,6 +7614,7 @@ $disabled-02: if(
- [select [mixin]](#select-mixin)
- [slider [mixin]](#slider-mixin)
- [tabs [mixin]](#tabs-mixin)
- [tags [mixin]](#tags-mixin)
- [text-area [mixin]](#text-area-mixin)
- [text-input [mixin]](#text-input-mixin)
- [toggle [mixin]](#toggle-mixin)
Expand Down Expand Up @@ -22044,7 +22045,8 @@ Tag styles
@include tag-theme($ibm-color__warm-gray-20, $ibm-color__warm-gray-100);
}

.#{$prefix}--tag--disabled {
.#{$prefix}--tag--disabled,
.#{$prefix}--tag--filter.#{$prefix}--tag--disabled {
@include tag-theme($ibm-color__gray-10, $ibm-color__gray-30);

&:hover {
Expand All @@ -22065,31 +22067,42 @@ Tag styles

cursor: pointer;
padding-right: rem(2px);

&:focus,
&:hover {
outline: none;
}
}

.#{$prefix}--tag--filter > svg {
fill: $inverse-01;
margin-left: rem(4px);
padding: rem(2px);
flex-shrink: 0;
width: rem(20px);
height: rem(20px);
}

.#{$prefix}--tag--filter > svg:hover {
margin: 0 0 0 rem(4px);
padding: rem(2px);
border: 0;
fill: $inverse-01;
background-color: transparent;
border-radius: 50%;
background-color: $inverse-hover-ui;
}

.#{$prefix}--tag--filter:focus,
.#{$prefix}--tag--filter:hover {
outline: none;
&:hover {
background-color: $inverse-hover-ui;
}
}

.#{$prefix}--tag--filter:focus > svg {
box-shadow: inset 0 0 0 2px $inverse-focus-ui;
border-radius: 50%;
}

.#{$prefix}--tag--filter.#{$prefix}--tag--disabled svg:hover {
background-color: transparent;
}

.#{$prefix}--tag--filter.#{$prefix}--tag--disabled svg {
fill: $disabled-02;
}

// Skeleton state
.#{$prefix}--tag.#{$prefix}--skeleton {
@include skeleton;
Expand All @@ -22114,6 +22127,7 @@ Tag styles
- [inverse-01 [variable]](#inverse-01-variable)
- [inverse-hover-ui [variable]](#inverse-hover-ui-variable)
- [inverse-focus-ui [variable]](#inverse-focus-ui-variable)
- [disabled-02 [variable]](#disabled-02-variable)

## text-area

Expand Down
36 changes: 24 additions & 12 deletions packages/components/src/components/tag/_tag.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
@include tag-theme($ibm-color__warm-gray-20, $ibm-color__warm-gray-100);
}

.#{$prefix}--tag--disabled {
.#{$prefix}--tag--disabled,
.#{$prefix}--tag--filter.#{$prefix}--tag--disabled {
@include tag-theme($ibm-color__gray-10, $ibm-color__gray-30);

&:hover {
Expand All @@ -97,31 +98,42 @@

cursor: pointer;
padding-right: rem(2px);

&:focus,
&:hover {
outline: none;
}
}

.#{$prefix}--tag--filter > svg {
fill: $inverse-01;
margin-left: rem(4px);
padding: rem(2px);
flex-shrink: 0;
width: rem(20px);
height: rem(20px);
}

.#{$prefix}--tag--filter > svg:hover {
margin: 0 0 0 rem(4px);
padding: rem(2px);
border: 0;
fill: $inverse-01;
background-color: transparent;
border-radius: 50%;
background-color: $inverse-hover-ui;
}

.#{$prefix}--tag--filter:focus,
.#{$prefix}--tag--filter:hover {
outline: none;
&:hover {
background-color: $inverse-hover-ui;
}
}

.#{$prefix}--tag--filter:focus > svg {
box-shadow: inset 0 0 0 2px $inverse-focus-ui;
border-radius: 50%;
}

.#{$prefix}--tag--filter.#{$prefix}--tag--disabled svg:hover {
background-color: transparent;
}

.#{$prefix}--tag--filter.#{$prefix}--tag--disabled svg {
fill: $disabled-02;
}

// Skeleton state
.#{$prefix}--tag.#{$prefix}--skeleton {
@include skeleton;
Expand Down
14 changes: 7 additions & 7 deletions packages/components/src/components/tag/tag.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
LICENSE file in the root directory of this source tree.
-->

<div role="list">
<div>
{{#each tags}}
<span class="{{@root.prefix}}--tag {{@root.prefix}}--tag--{{type}}" role="listitem">
<button class="{{@root.prefix}}--tag {{@root.prefix}}--tag--{{type}}">
<span class="{{@root.prefix}}--tag__label">{{label}}</span>
</span>
</button>
{{/each}}
</div>

<div role="list">
<div>
{{#if filter}}
<span class="{{@root.prefix}}--tag {{@root.prefix}}--tag--filter" title="Clear filter" tabindex="0" role="listitem">
<button class="{{@root.prefix}}--tag {{@root.prefix}}--tag--filter" title="Clear filter">
<span class="{{@root.prefix}}--tag__label">filter</span>
{{ carbon-icon 'Close16' aria-label='Clear filter' }}
</span>
{{ carbon-icon 'Close16' }}
</button>
{{/if}}
</div>
2 changes: 1 addition & 1 deletion packages/elements/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function build() {
const paths = klaw(BUNDLE_DIR, {
nodir: true,
filter(item) {
const paths = item.path.split('/');
const paths = item.path.split(path.sep);
const filename = paths[paths.length - 1];
const folder = paths[paths.length - 3];

Expand Down
9 changes: 7 additions & 2 deletions packages/icon-build-helpers/src/builders/react/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'use strict';

const { camel } = require('change-case');
const { reporter } = require('@carbon/cli-reporter');
const fs = require('fs-extra');
const path = require('path');
const { rollup } = require('rollup');
Expand Down Expand Up @@ -71,6 +72,7 @@ ${modules.map(({ source }) => `export ${source}`).join('\n')}
export { Icon };
`;

reporter.info('Building components');
const bundle = await rollup({
input: '__entrypoint__.js',
external,
Expand Down Expand Up @@ -106,6 +108,7 @@ export { Icon };
})
);

reporter.info('Creating aliases');
// Create aliases for `@carbon/icons-react/es/<icon-name>/<size>`
await Promise.all(
meta.map(async icon => {
Expand All @@ -114,7 +117,7 @@ export { Icon };
// The length of this is determined by the number of directories from
// our `outputOptions` minus 1 for the bundle type (`es` for example)
// and minus 1 for the filename as it does not count as a directory jump
length: outputOptions.file.split('/').length - 2,
length: outputOptions.file.split(path.sep).length - 2,
})
.fill('..')
.join('/');
Expand All @@ -141,7 +144,7 @@ export default ${moduleName};
// Drop the first part of `outputOptions.file` as it contains the `es/`
// directory
const commonjsFilepath = outputOptions.file
.split('/')
.split(path.sep)
.slice(1)
.join('/');
const { source: component } = createIconComponent(moduleName, descriptor);
Expand All @@ -165,6 +168,7 @@ export default ${moduleName};`;
};
}, {});

reporter.info('Bundling Javascript modules');
// Using the mapping of file path to file source, we can specify our input to
// rollup by formatting the filepath so that rollup outputs the file to the
// correct place. The location is going to match the key that we use in the
Expand Down Expand Up @@ -200,6 +204,7 @@ export default ${moduleName};`;
],
});

reporter.info('Writing to destination');
await commonjsBundles.write({
dir: 'lib',
format: 'cjs',
Expand Down
5 changes: 4 additions & 1 deletion packages/icon-build-helpers/src/builders/vanilla/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,16 @@ async function builder(source, { cwd } = {}) {
function getModuleName(name, size, prefixParts, descriptor) {
const width = parseInt(descriptor.attrs.width, 10);
const height = parseInt(descriptor.attrs.height, 10);
const prefix = prefixParts
let prefix = prefixParts
.filter(size => isNaN(size))
.map(pascal)
.join('');
const isGlyph = width < 16 || height < 16;

if (prefix !== '') {
if (prefix.match(/^\d/)) {
prefix = '_' + prefix;
}
if (!size) {
if (isGlyph) {
return prefix + pascal(name) + 'Glyph';
Expand Down
Loading

0 comments on commit 7145b82

Please sign in to comment.