fix(css): box-shadow none handling (#10445)

closes https://github.com/NativeScript/NativeScript/issues/10403
This commit is contained in:
Nathan Walker
2023-11-19 15:30:07 -08:00
committed by GitHub
parent 5b9d861fa3
commit 67440095f4
7 changed files with 20 additions and 33 deletions

View File

@ -221,4 +221,8 @@ Button {
.switch-demo-page Switch.custom-switch:disabled:checked { .switch-demo-page Switch.custom-switch:disabled:checked {
color: #ddd; color: #ddd;
background-color: #777; background-color: #777;
}
.no-shadow {
box-shadow: none;
} }

View File

@ -9,7 +9,7 @@
<!-- layouts --> <!-- layouts -->
<ScrollView height="100%" visibility="{{ selectedComponentType === 'layouts' ? 'visible' : 'collapsed' }}"> <ScrollView height="100%" visibility="{{ selectedComponentType === 'layouts' ? 'visible' : 'collapsed' }}">
<StackLayout padding="20"> <StackLayout padding="20">
<StackLayout width="300" height="100" class="demo-component" boxShadow="{{ appliedBoxShadow }}" borderColor="{{ borderColor }}" borderWidth="{{ borderWidth }}" borderRadius="{{ borderRadius }}" background="{{ background }}" tap="{{ toggleAnimation }}"> <StackLayout width="300" height="100" class="demo-component" boxShadow="{{ appliedBoxShadow }}" borderColor="{{ borderColor }}" borderWidth="{{ borderWidth }}" borderRadius="{{ borderRadius }}" background="{{ background }}" tap="{{ toggleAnimation }}">
<Label text="StackLayout" /> <Label text="StackLayout" />
</StackLayout> </StackLayout>
@ -40,10 +40,12 @@
</GridLayout> </GridLayout>
<!-- buttons --> <!-- buttons -->
<GridLayout rows="*" height="100%" visibility="{{ selectedComponentType === 'buttons' ? 'visible' : 'collapsed' }}"> <GridLayout rows="*,*" height="100%" visibility="{{ selectedComponentType === 'buttons' ? 'visible' : 'collapsed' }}">
<Button horizontalAlignment="center" verticalAlignment="center" class="demo-component" boxShadow="{{ appliedBoxShadow }}" borderColor="{{ borderColor }}" borderWidth="{{ borderWidth }}" borderRadius="{{ borderRadius }}" background="{{ background }}" tap="{{ toggleAnimation }}" text="button" /> <Button horizontalAlignment="center" verticalAlignment="center" class="demo-component" boxShadow="{{ appliedBoxShadow }}" borderColor="{{ borderColor }}" borderWidth="{{ borderWidth }}" borderRadius="{{ borderRadius }}" background="{{ background }}" tap="{{ toggleAnimation }}" text="button" />
<Button row="1" horizontalAlignment="center" verticalAlignment="center" class="demo-component no-shadow" text="button no shadow" />
</GridLayout> </GridLayout>
<!-- images --> <!-- images -->

View File

@ -6,12 +6,7 @@ import { Color } from '../../color';
describe('css-shadow', () => { describe('css-shadow', () => {
it('empty', () => { it('empty', () => {
const shadow = parseCSSShadow(''); const shadow = parseCSSShadow('');
expect(shadow.inset).toBe(false); expect(shadow).toBeNull();
expect(shadow.offsetX).toBeUndefined();
expect(shadow.offsetY).toBeUndefined();
expect(shadow.blurRadius).toBeUndefined();
expect(shadow.spreadRadius).toBeUndefined();
expect(shadow.color).toBeUndefined();
}); });
it('1px 1px 2px black', () => { it('1px 1px 2px black', () => {
@ -137,33 +132,18 @@ describe('css-shadow', () => {
it('none', () => { it('none', () => {
const shadow = parseCSSShadow('none'); const shadow = parseCSSShadow('none');
expect(shadow.inset).toBe(false); expect(shadow).toBeNull();
expect(shadow.offsetX).toBeUndefined();
expect(shadow.offsetY).toBeUndefined();
expect(shadow.blurRadius).toBeUndefined();
expect(shadow.spreadRadius).toBeUndefined();
expect(shadow.color).toBeUndefined();
}); });
it('unset', () => { it('unset', () => {
const shadow = parseCSSShadow('unset'); const shadow = parseCSSShadow('unset');
expect(shadow.inset).toBe(false); expect(shadow).toBeNull();
expect(shadow.offsetX).toBeUndefined();
expect(shadow.offsetY).toBeUndefined();
expect(shadow.blurRadius).toBeUndefined();
expect(shadow.spreadRadius).toBeUndefined();
expect(shadow.color).toBeUndefined();
}); });
it('unset 5em 1em gold', () => { it('unset 5em 1em gold', () => {
// invalid shorthand should result in nothing being applied // invalid shorthand should result in nothing being applied
const shadow = parseCSSShadow('unset 5em 1em gold'); const shadow = parseCSSShadow('unset 5em 1em gold');
expect(shadow.inset).toBe(false); expect(shadow).toBeNull();
expect(shadow.offsetX).toBeUndefined();
expect(shadow.offsetY).toBeUndefined();
expect(shadow.blurRadius).toBeUndefined();
expect(shadow.spreadRadius).toBeUndefined();
expect(shadow.color).toBeUndefined();
}); });
it('5em 1em gold unset', () => { it('5em 1em gold unset', () => {

View File

@ -21,6 +21,9 @@ export interface ShadowCSSValues {
*/ */
export function parseCSSShadow(value: string): ShadowCSSValues { export function parseCSSShadow(value: string): ShadowCSSValues {
const data = parseCSSShorthand(value); const data = parseCSSShorthand(value);
if (!data) {
return null;
}
const [offsetX, offsetY, blurRadius, spreadRadius] = data.values; const [offsetX, offsetY, blurRadius, spreadRadius] = data.values;
return { return {

View File

@ -6,8 +6,7 @@ import { Color } from '../../color';
describe('css-text-stroke', () => { describe('css-text-stroke', () => {
it('empty', () => { it('empty', () => {
const stroke = parseCSSStroke(''); const stroke = parseCSSStroke('');
expect(stroke.width).toBeUndefined(); expect(stroke).toBeNull();
expect(stroke.color).toBeUndefined();
}); });
it('1px navy', () => { it('1px navy', () => {

View File

@ -14,6 +14,9 @@ export interface StrokeCSSValues {
*/ */
export function parseCSSStroke(value: string): StrokeCSSValues { export function parseCSSStroke(value: string): StrokeCSSValues {
const data = parseCSSShorthand(value); const data = parseCSSShorthand(value);
if (!data) {
return null;
}
const [width] = data.values; const [width] = data.values;
return { return {

View File

@ -37,11 +37,7 @@ export function parseCSSShorthand(value: string): {
const first = parts[0]; const first = parts[0];
if (['', 'none', 'unset'].includes(first)) { if (['', 'none', 'unset'].includes(first)) {
return { return null;
inset: false,
color: undefined,
values: [],
};
} else { } else {
const invalidColors = ['inset', 'unset']; const invalidColors = ['inset', 'unset'];
const inset = parts.includes('inset'); const inset = parts.includes('inset');