Skip to content

Commit 76fad2f

Browse files
Merge pull request #9 from reflect-ui/support-text-shadow
support text shadow
2 parents 01478e5 + a9afb98 commit 76fad2f

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

packages/reflect-core/lib/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export * from "./font-weight";
2020
export * from "./font-style";
2121
export * from "./icon";
2222
export * from "./image";
23+
export * from "./letter-spacing";
2324
export * from "./linear-gradient";
2425
export * from "./gradient";
2526
export * from "./opacity";
@@ -32,6 +33,7 @@ export * from "./text-shadow";
3233
export * from "./text-align";
3334
export * from "./text-decoration";
3435
export * from "./text-overflow";
36+
export * from "./text-shadow";
3537
export * from "./rect";
3638
export * from "./radius";
3739
export * from "./edge-insets";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* css: https://developer.mozilla.org/en-US/docs/Web/CSS/letter-spacing
3+
*
4+
* flutter: https://api.flutter.dev/flutter/painting/TextStyle/letterSpacing.html
5+
*
6+
* flutter letter spacing unit is pixel phttps://github.com/flutter/flutter/blob/18116933e7/packages/flutter/lib/src/painting/text_style.dart#L592
7+
*
8+
* figma: `type LetterSpacing = {
9+
* value: number;
10+
* unit: "PIXELS" | "PERCENT";
11+
* };
12+
*/
13+
14+
/**
15+
* css supports various units, flutter only supports px.
16+
* However, the figma we currently support supports pixels and percent,
17+
* so only two units are used.
18+
*
19+
* In the future, what is used as DimensionLength will also be converted and integrated into the following format.
20+
*/
21+
22+
type Unit = "PIXELS" | "PERCENT";
23+
24+
export type LetterSpacing = {
25+
value: number;
26+
unit: Unit;
27+
};
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
import { Color } from "../color";
22
import { Offset } from "../offset";
3-
import { BlendMode } from "../cg/filters";
4-
import { RGBA } from "../color";
5-
import { Vector } from "../uiutils/types";
63

74
/**
5+
*
6+
* [css](https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow)
7+
*
8+
* [flutter](https://api.flutter.dev/flutter/dart-ui/Shadow-class.html)
9+
*
10+
* [w3](https://www.w3.org/TR/css-text-decor-4/#propdef-text-shadow)
11+
*
12+
* figma: https://www.figma.com/plugin-docs/api/Effect/#dropshadoweffect
13+
*
814
* Currently not supporting inner shadow
15+
*
916
*/
17+
1018
export interface TextShadow {
1119
color: Color;
1220
offset: Offset;
1321
blurRadius: number;
14-
spreadRadius: number;
22+
/**
23+
* According to W3C, `geometry of a glyph is not so simple as a box`.It is likely to be added later.
24+
*/
25+
spreadRadius?: number;
1526
}
1627

1728
export type TextShadowManifest = TextShadow;

packages/reflect-core/lib/text-style/text-style.manifest.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { LetterSpacing } from "@design-sdk/figma-types";
2-
import { DimensionLength, TextShadowManifest } from "..";
1+
import { DimensionLength, TextShadowManifest, LetterSpacing } from "..";
32
import { ColorManifest } from "../color";
43
import { FontStyleManifest } from "../font-style";
54
import { FontWeightManifest } from "../font-weight";
@@ -62,6 +61,13 @@ export interface ITextStyle {
6261
lineHeight?: DimensionLength;
6362
// endregion spacing related
6463

64+
/**
65+
* textShadow supports multiple shadows in css and flutter.
66+
*
67+
* [css](https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow)
68+
*
69+
* [flutter](https://api.flutter.dev/flutter/painting/TextStyle/shadows.html)
70+
*/
6571
textShadow?: TextShadowManifest[];
6672
}
6773

packages/reflect-core/lib/text-style/text-style.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { LetterSpacing } from "@design-sdk/figma-types";
1+
import { LetterSpacing } from "../letter-spacing";
22
import { DimensionLength } from "..";
33
import { Color, Colors } from "../color";
44
import { FontStyle } from "../font-style";
55
import { FontWeight } from "../font-weight";
66
import { TextDecoration, TextDecorationStyle } from "../text-decoration";
7+
import { TextShadow } from "../text-shadow";
78
import { ITextStyle as ITextStyle } from "./text-style.manifest";
89
export class TextStyle implements ITextStyle {
910
fontFamily: string;
@@ -18,6 +19,7 @@ export class TextStyle implements ITextStyle {
1819
letterSpacing: LetterSpacing;
1920
wordSpacing?: number;
2021
lineHeight: DimensionLength;
22+
textShadow: TextShadow[];
2123

2224
constructor({
2325
fontFamily,
@@ -32,6 +34,7 @@ export class TextStyle implements ITextStyle {
3234
letterSpacing,
3335
wordSpacing,
3436
lineHeight,
37+
textShadow,
3538
}: ITextStyle) {
3639
this.fontFamily = fontFamily;
3740
this.fontWeight = fontWeight;
@@ -45,5 +48,6 @@ export class TextStyle implements ITextStyle {
4548
this.letterSpacing = letterSpacing;
4649
this.wordSpacing = wordSpacing;
4750
this.lineHeight = lineHeight;
51+
this.textShadow = textShadow;
4852
}
4953
}

0 commit comments

Comments
 (0)