Skip to content

Commit fe6351c

Browse files
committed
feat: new MD Color Schemes
1 parent 8342947 commit fe6351c

58 files changed

Lines changed: 10473 additions & 751 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ src/core/framework7-lite.js
1414
src/core/modules/demo-module.js
1515
src/core/modules/component/snabbdom
1616
src/core/shared/material-color-utils.js
17+
src/material-color-utilities
1718
woff2
1819

1920
src/vue-temp

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ kitchen-sink/svelte/dist
1212
kitchen-sink/**/*.json
1313
src/vue-temp
1414
src/core/shared/material-color-utils.js
15+
src/material-color-utilities
1516
.nova
1617
package.json

kitchen-sink/core/pages/color-themes.html

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,41 @@
7575
`)}
7676
</div>
7777
</div>
78+
79+
<div class="block-title block-title-medium">Material Color Scheme</div>
80+
<div class="list list-strong inset">
81+
<ul>
82+
<li>
83+
<label class="item-content">
84+
<div class="item-inner">
85+
<div class="item-title">Monochrome</div>
86+
<div class="item-after">
87+
<div class="toggle toggle-init">
88+
<input type="checkbox" checked=${monochrome} @change=${(e)=>
89+
setMdColorSchemeMonochrome(e.target.checked)} />
90+
<span class="toggle-icon"></span>
91+
</div>
92+
</div>
93+
</div>
94+
</label>
95+
</li>
96+
<li>
97+
<label class="item-content">
98+
<div class="item-inner">
99+
<div class="item-title">Vibrant</div>
100+
<div class="item-after">
101+
<div class="toggle toggle-init">
102+
<input type="checkbox" checked=${vibrant} @change=${(e)=> setMdColorSchemeVibrant(e.target.checked)}
103+
/>
104+
<span class="toggle-icon"></span>
105+
</div>
106+
</div>
107+
</div>
108+
</label>
109+
</li>
110+
</ul>
111+
</div>
112+
78113
<div class="block-title block-title-medium">Custom Color Theme</div>
79114
<div class="list list-strong-ios list-outline-ios">
80115
<ul>
@@ -104,6 +139,8 @@
104139
const colors = Object.keys($f7.colors).filter((c) => c !== 'primary' && c !== 'white' && c !== 'black');
105140

106141
let colorPicker;
142+
let monochrome = false;
143+
let vibrant = false;
107144

108145
const setScheme = (newTheme) => {
109146
$f7.setDarkMode(newTheme === 'dark');
@@ -126,6 +163,28 @@
126163
$update();
127164
}
128165

166+
const setMdColorScheme = () => {
167+
if (!vibrant && !monochrome) {
168+
$f7.setMdColorScheme('default');
169+
} else if (vibrant && !monochrome) {
170+
$f7.setMdColorScheme('vibrant');
171+
} else if (!vibrant && monochrome) {
172+
$f7.setMdColorScheme('monochrome');
173+
} else if (vibrant && monochrome) {
174+
$f7.setMdColorScheme('vibrant-monochrome');
175+
}
176+
$update();
177+
}
178+
179+
const setMdColorSchemeMonochrome = (value) => {
180+
monochrome = value;
181+
setMdColorScheme();
182+
}
183+
const setMdColorSchemeVibrant = (value) => {
184+
vibrant = value;
185+
setMdColorScheme();
186+
}
187+
129188
$on('pageInit', () => {
130189
let timeout;
131190
colorPicker = $f7.colorPicker.create({
@@ -152,4 +211,4 @@
152211
return $render;
153212
};
154213

155-
</script>
214+
</script>

package-lock.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
"@babel/core": "^7.19.3",
7979
"@babel/preset-env": "^7.19.4",
8080
"@babel/preset-react": "^7.18.6",
81-
"@material/material-color-utilities": "^0.2.4",
8281
"@rollup/plugin-babel": "^6.0.0",
8382
"@rollup/plugin-commonjs": "^23.0.0",
8483
"@rollup/plugin-node-resolve": "^15.0.0",

scripts/build-material-color-utils.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,13 @@ const path = require('path');
33
const { rollup } = require('rollup');
44
const { nodeResolve } = require('@rollup/plugin-node-resolve');
55
const commonjs = require('@rollup/plugin-commonjs');
6-
const virtual = require('@rollup/plugin-virtual');
76
const { minify } = require('terser');
87

98
async function build(cb) {
109
const outputFile = path.resolve(__dirname, '../src/core/shared/material-color-utils.js');
1110
await rollup({
12-
input: 'entry',
13-
plugins: [
14-
virtual({
15-
entry: `export { argbFromHex, hexFromArgb, themeFromSourceColor } from '@material/material-color-utilities';`,
16-
}),
17-
nodeResolve({ mainFields: ['module', 'main', 'jsnext'] }),
18-
commonjs(),
19-
],
11+
input: path.resolve(__dirname, '../src/material-color-utilities/source.js'),
12+
plugins: [nodeResolve({ mainFields: ['module', 'main', 'jsnext'] }), commonjs()],
2013
})
2114
.then((bundle) => {
2215
return bundle.write({

src/core/components/app/app-class.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export interface Framework7Parameters {
6363
iosTranslucentModals?: boolean;
6464
/** Object with app colors where `primary` color (key) defines main app color theme */
6565
colors?: object;
66+
/** Material color scheme. Can be `default`, `vibrant`, `monochrome` or `monochrome-vibrant` */
67+
mdColorScheme?: string;
6668
/** userAgent string. Required for browser/device detection when rendered on server-side */
6769
userAgent?: string;
6870
/** Required for current route detection when rendered on server-side */

src/core/components/app/app-class.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Framework7 extends Framework7Class {
5151
componentUrl: undefined,
5252
userAgent: null,
5353
url: null,
54+
mdColorScheme: 'default',
5455
colors: {
5556
primary: '#007aff',
5657
red: '#ff3b30',
@@ -95,6 +96,7 @@ class Framework7 extends Framework7Class {
9596
passedParams,
9697
online: w.navigator.onLine,
9798
colors: app.params.colors,
99+
mdColorScheme: app.params.mdColorScheme || 'default',
98100
darkMode: app.params.darkMode,
99101
});
100102

@@ -126,10 +128,17 @@ class Framework7 extends Framework7Class {
126128
return app;
127129
}
128130

129-
setColorTheme(color) {
131+
setColorTheme(color, mdColorScheme) {
130132
if (!color) return;
131133
const app = this;
132134
app.colors.primary = color;
135+
app.mdColorScheme = mdColorScheme || app.mdColorScheme;
136+
app.setColors();
137+
}
138+
139+
setMdColorScheme(mdColorScheme) {
140+
const app = this;
141+
app.mdColorScheme = mdColorScheme || app.mdColorScheme;
133142
app.setColors();
134143
}
135144

@@ -141,7 +150,7 @@ class Framework7 extends Framework7Class {
141150
document.head.prepend(app.colorsStyleEl);
142151
}
143152

144-
app.colorsStyleEl.textContent = app.utils.colorThemeCSSStyles(app.colors);
153+
app.colorsStyleEl.textContent = app.utils.colorThemeCSSStyles(app.colors, app.mdColorScheme);
145154
}
146155

147156
mount(rootEl) {

0 commit comments

Comments
 (0)