-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from cfpb/ans_update
Update to latest DS
- Loading branch information
Showing
23 changed files
with
768 additions
and
730 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ | |
** | ||
|
||
# ...except for all of this | ||
!esbuild.mjs | ||
!esbuild/**/*.js | ||
|
||
!manage.py | ||
!package.json | ||
!settings.py | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import esbuild from "esbuild"; | ||
|
||
import { scripts } from "./scripts.js"; | ||
|
||
const baseConfig = { | ||
logLevel: "info", | ||
bundle: true, | ||
minify: true, | ||
sourcemap: true, | ||
external: ["*.png", "*.woff2", "*.gif"], | ||
loader: { | ||
".svg": "text", | ||
}, | ||
outdir: "./viewer/static", | ||
outbase: "./viewer/static_src", | ||
plugins: [], | ||
}; | ||
|
||
const arg = process.argv.slice(2)[0]; | ||
|
||
(async function () { | ||
const scriptsConfig = scripts(baseConfig); | ||
|
||
if (arg === "watch") { | ||
const ctx = await esbuild.context(scriptsConfig); | ||
await ctx.watch(); | ||
// Not disposing context here as the user will ctrl+c to end watching. | ||
} else { | ||
const ctx = await esbuild.context(scriptsConfig); | ||
await ctx.rebuild(); | ||
await ctx.dispose(); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { readdirSync } from "node:fs"; | ||
import postcss from "postcss"; | ||
import * as sass from "sass"; | ||
import { pluginProcessIcons } from "./postcss-process-icons.js"; | ||
|
||
const pluginPostCssSass = ({ plugins = [] }) => ({ | ||
name: "postcss-sass", | ||
setup(build) { | ||
build.onLoad({ filter: /.\.scss$/ }, async (args) => { | ||
const sassResult = await sass.compile(args.path, { | ||
loadPaths: [ | ||
...readdirSync("./node_modules/@cfpb").map( | ||
(v) => `./node_modules/@cfpb/${v}/src`, | ||
), | ||
"./node_modules/", | ||
], | ||
}); | ||
|
||
const result = await postcss([...plugins, pluginProcessIcons]).process( | ||
sassResult.css, | ||
{ | ||
from: args.path, | ||
}, | ||
); | ||
|
||
return { | ||
contents: result.css, | ||
loader: "css", | ||
}; | ||
}); | ||
}, | ||
}); | ||
|
||
export { pluginPostCssSass }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { readFileSync } from "node:fs"; | ||
import { fileURLToPath } from "url"; | ||
import { dirname } from "path"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
const pluginProcessIcons = () => { | ||
const stripQuotes = (str) => str.replace(/['"]+/g, ""); | ||
|
||
return { | ||
postcssPlugin: "process-icons", | ||
Declaration: { | ||
"--cfpb-background-icon-svg": async (decl) => { | ||
const props = decl.value.split(" "); | ||
const iconName = stripQuotes(props[0]); | ||
const iconColor = props.length > 1 ? stripQuotes(props[1]) : ""; | ||
|
||
const pathToSVG = | ||
__dirname + | ||
"/../../node_modules/@cfpb/cfpb-design-system/src/components/cfpb-icons/icons/" + | ||
iconName + | ||
".svg"; | ||
const rawSVG = await readFileSync(pathToSVG, "utf8", (err, data) => { | ||
if (err) console.log(err); | ||
|
||
return data; | ||
}); | ||
|
||
let cleanSVG = rawSVG; | ||
if (iconColor !== "") { | ||
cleanSVG = rawSVG.replace( | ||
/class="cf-icon-svg .+" /, | ||
`fill="${iconColor}" `, | ||
); | ||
} | ||
|
||
decl.prop = "background-image"; | ||
decl.value = `url('data:image/svg+xml;charset=UTF-8,${cleanSVG}')`; | ||
}, | ||
}, | ||
}; | ||
}; | ||
pluginProcessIcons.postcss = true; | ||
|
||
export { pluginProcessIcons }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { pluginPostCssSass } from "./plugins/plugin-postcss-sass.js"; | ||
import { copy } from "esbuild-plugin-copy"; | ||
import autoprefixer from "autoprefixer"; | ||
|
||
const jsPaths = []; | ||
|
||
const entryFileList = ["./viewer/static_src/js/main.js"]; | ||
entryFileList.forEach((file) => { | ||
jsPaths.push(file); | ||
}); | ||
|
||
/** | ||
* @param {object} baseConfig - The base esbuild configuration. | ||
* @returns {object} The modified configuration object. | ||
*/ | ||
function scripts(baseConfig) { | ||
return { | ||
...baseConfig, | ||
entryPoints: jsPaths, | ||
target: "es6", | ||
plugins: baseConfig.plugins.concat([ | ||
copy({ | ||
assets: [ | ||
{ | ||
from: ["./viewer/static_src/query-string-filtering.docx"], | ||
to: ["."], | ||
}, | ||
{ | ||
from: [ | ||
"./node_modules/@cfpb/cfpb-design-system/src/components/cfp-icons/icons/*", | ||
], | ||
to: ["./icons"], | ||
}, | ||
], | ||
}), | ||
pluginPostCssSass({ | ||
plugins: [autoprefixer], | ||
}), | ||
copy({ | ||
assets: [ | ||
{ | ||
from: ["./viewer/static/js/main.css"], | ||
to: ["./css/main.css"], | ||
}, | ||
{ | ||
from: ["./viewer/static/js/main.css.map"], | ||
to: ["./css/main.css.map"], | ||
}, | ||
], | ||
}), | ||
]), | ||
}; | ||
} | ||
|
||
export { scripts }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 12 additions & 9 deletions
21
viewer/static_src/css/breadcrumbs.less → viewer/static_src/css/breadcrumbs.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
@use "sass:math"; | ||
@use "@cfpb/cfpb-design-system/src/abstracts" as *; | ||
|
||
// Copied from https://github.com/cfpb/consumerfinance.gov/blob/f19227f9d13d90f19c06dd1dbd78e9233d1d3432/cfgov/unprocessed/css/breadcrumbs.less | ||
.m-breadcrumbs { | ||
// Mobile size. | ||
position: relative; | ||
display: flex; | ||
gap: unit(10px / @base-font-size-px, rem); | ||
gap: math.div(10px, $base-font-size-px) + rem; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
|
||
font-size: unit(14px / @base-font-size-px, rem); | ||
padding-top: unit(15px / @base-font-size-px, rem); | ||
padding-bottom: unit(15px / @base-font-size-px, rem); | ||
font-size: math.div(14px, $base-font-size-px) + rem; | ||
padding-top: math.div(15px, $base-font-size-px) + rem; | ||
padding-bottom: math.div(15px, $base-font-size-px) + rem; | ||
min-height: 33px; | ||
|
||
// Desktop and above. | ||
.respond-to-min(@bp-med-min, { | ||
padding-top: unit(30px / @base-font-size-px, rem); | ||
@include respond-to-min($bp-med-min) { | ||
padding-top: math.div(30px, $base-font-size-px) + rem; | ||
// Bottom is zero because main content area may or may not have a breadcrumb, | ||
// so the main content needs to set it s own spacing. | ||
padding-bottom: 0; | ||
}); | ||
} | ||
} | ||
|
||
// Hide on print. | ||
.respond-to-print({ | ||
@include respond-to-print() { | ||
.m-breadcrumbs { | ||
display: none; | ||
} | ||
}); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.