mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 18:12:09 +08:00
fix(css): box-shadow none handling (#10445)
closes https://github.com/NativeScript/NativeScript/issues/10403
This commit is contained in:
@ -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;
|
||||||
}
|
}
|
@ -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 -->
|
||||||
|
@ -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', () => {
|
||||||
|
@ -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 {
|
||||||
|
@ -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', () => {
|
||||||
|
@ -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 {
|
||||||
|
@ -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');
|
||||||
|
Reference in New Issue
Block a user