Skip to content

support text shadow #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
23ce9db
add shadow effect docs
You-J Oct 19, 2021
651a678
Merge branch 'main' of https://github.com/gridaco/designto-code into …
You-J Oct 19, 2021
970d396
add text shadow in css
You-J Oct 20, 2021
718ce9b
add text shadow without flutter
You-J Oct 21, 2021
cdeda66
update reflect-core
You-J Oct 21, 2021
9366ccf
Merge branch 'main' of https://github.com/gridaco/designto-code into …
You-J Oct 21, 2021
8ebc579
add dart ui shadow
You-J Oct 22, 2021
af45903
update flutter-builder
You-J Oct 26, 2021
fc56f3f
update packages
You-J Oct 28, 2021
831de31
update reflect core letterspacing type
You-J Oct 29, 2021
2906746
Merge branch 'main' of https://github.com/gridaco/designto-code into …
You-J Oct 29, 2021
911a61d
update text shadow docs
You-J Nov 3, 2021
1dfbf83
fix typo and remove comment
You-J Nov 5, 2021
23a6d99
update relfect-core
You-J Nov 5, 2021
9d9142b
add handle like 0% in length
You-J Nov 5, 2021
79254c4
update docs
You-J Nov 5, 2021
8075681
update design-sdk
You-J Nov 5, 2021
7026d43
update reflect core
You-J Nov 5, 2021
cbb2355
Add more context in `Why text shadow isn't support spread radius?` docs
softmarshmallow Nov 5, 2021
122ac1e
add dart-ui/Shadow-class link comment s
You-J Nov 5, 2021
bbfb611
update reflect-core
You-J Nov 5, 2021
e5a50ca
Merge branch 'support-text-shadow' of https://github.com/gridaco/desi…
You-J Nov 5, 2021
bcb45f9
update reflect-core to local
You-J Nov 5, 2021
875e42f
update design-sdk to local
You-J Nov 5, 2021
a7bd26b
Merge branch 'main' of https://github.com/gridaco/designto-code into …
You-J Nov 5, 2021
e8cc0ef
update yarn lock
You-J Nov 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/figma-text-shadow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Figma text shadow

The text shadow is handled as the shadow of the effect from figma.

![](https://static.figma.com/uploads/9def6cce093b164306328ee228028155d13d72d0)

[figma DropShadowEffect](https://www.figma.com/plugin-docs/api/Effect/#dropshadoweffect)

[W3C](https://www.w3.org/TR/css-text-decor-4/#propdef-text-shadow)

## drop-shadow

**css**

- [`text-shadow`](https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow)

**syntax**

1. offsetX offsetY blurRadius color
2. color offsetX offsetY blurRadius
3. offsetX offsetY color
4. color offsetX offsetY

```css
text-shadow: 1px 1px 2px #ff2;
text-shadow: 1px 1px 2px red, 0 0 1em blue, 0 0 0.2em blue;
```

**flutter**

- [`Shadow`](https://api.flutter.dev/flutter/dart-ui/Shadow-class.html)

```dart
Shadow(
offset: Offset(10.0, 10.0),
blurRadius: 3.0,
color: Color.fromARGB(255, 0, 0, 0),
)
```

### inner-shadow

It is not currently supported, and it appears to be replaced with drop-shadow.

## Why text shadow isn't support `spread radius`?

The spread radius, the 4th arg of box shadow, is not supported by text shadow. According to W3C,
It says `geometry of a glyph is not so simple as a box`. It is likely to be added later.
1 change: 0 additions & 1 deletion editor/pages/figma/inspect-raw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default function InspectRaw() {
}
const { node, reflect, raw, remote, figma } = design;
//

return (
<>
<MonacoEditor
Expand Down
1 change: 1 addition & 0 deletions packages/builder-css-styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from "./dimensions";
export * from "./font-weight";
export * from "./font-family";
export * from "./text-decoration";
export * from "./text-shadow";
export * from "./gradient";
export * from "./padding";
export * from "./position";
Expand Down
5 changes: 5 additions & 0 deletions packages/builder-css-styles/length/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export function length(d: DimensionLength | string, a?: Axis) {
}

if (typeof d === "string") {
// To handle cases such as "0%"
const extractNum = d.replace(/[^0-9]/, "");
if (parseInt(extractNum) === 0) {
return;
}
if (d === "match-screen-size") {
switch (a) {
case Axis.horizontal:
Expand Down
17 changes: 17 additions & 0 deletions packages/builder-css-styles/text-shadow/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { TextShadowManifest } from "@reflect-ui/core";
import { color } from "../color";
import { px } from "../dimensions";

export function textShadow(ts: TextShadowManifest[]): string {
if (ts.length === 0) {
return;
}

const res = ts.map((shadow) => {
return `${px(shadow.offset.dx)} ${px(shadow.offset.dy)} ${px(
shadow.blurRadius
)} ${color(shadow.color)}`;
});

return res.toString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class Text extends TextChildWidget {
"line-height": css.length(this.textStyle.lineHeight),
"text-align": this.textAlign,
"text-decoration": css.textDecoration(this.textStyle.decoration),
"text-shadow": css.textShadow(this.textStyle.textShadow),
// ------------------------------------------
"min-height": css.px(this.height),
// TODO: do not specify width when parent is a flex container.
Expand Down
2 changes: 1 addition & 1 deletion packages/coli
Submodule coli updated from 83d3cb to 519de9
2 changes: 1 addition & 1 deletion packages/design-sdk
2 changes: 1 addition & 1 deletion packages/designto-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@designto/web": "0.0.0",
"@design-sdk/universal": "0.0.0",
"@reflect-ui/detection": "0.1.1",
"@flutter-builder/flutter": "2.5.0-f13"
"@flutter-builder/flutter": "2.5.0-f16"
},
"files": [
"README.md",
Expand Down
32 changes: 32 additions & 0 deletions packages/designto-flutter/dart-ui/dart-ui-shadow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as flutter from "@flutter-builder/flutter";
import * as dartui from ".";
import { roundNumber } from "@reflect-ui/uiutils";
import { TextShadowManifest } from "@reflect-ui/core";

export function shadow(
shadows: ReadonlyArray<TextShadowManifest>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convention not matching. is it correct that Shadow exists under dartui on official flutter docs?

Copy link
Collaborator Author

@You-J You-J Nov 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. still the name and input type does not match intuitively, please add the link - https://api.flutter.dev/flutter/dart-ui/Shadow-class.html to jsdoc for shadow func

): Array<flutter.Shadow> {
// if no shadow filtered available, return undefined
if (shadows.length == 0) {
return undefined;
}

const _shadows = shadows.map((d: TextShadowManifest) => {
return new flutter.Shadow({
color: dartui.color(d.color),
blurRadius: requiredNumber(d.blurRadius),
offset: dartui.offset(d.offset),
});
});

// return undefined if array is empty, since it's not needed.
return _shadows.length > 0 ? _shadows : undefined;
}

function requiredNumber(number: number): number {
const rounded = roundNumber(number);
if (rounded == 0) {
return undefined;
}
return rounded;
}
1 change: 1 addition & 0 deletions packages/designto-flutter/dart-ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from "./dart-ui-clip";
export * from "./dart-ui-color";
export * from "./dart-ui-offset";
export * from "./dart-ui-radius";
export * from "./dart-ui-shadow";
export * from "./dart-ui-text-align";
4 changes: 4 additions & 0 deletions packages/designto-flutter/painting/painting-box-shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function boxShadow(

const boxShadows: Array<flutter.BoxShadow> = shadows.map(
(d: BoxShadowManifest) => {
if (!d) {
return;
}

return new flutter.BoxShadow({
color: dartui.color(d.color),
blurRadius: requiredNumber(d.blurRadius),
Expand Down
4 changes: 3 additions & 1 deletion packages/designto-flutter/painting/painting-text-style.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ITextStyle } from "@reflect-ui/core";
import type { ITextStyle, TextShadowManifest } from "@reflect-ui/core";
import * as flutter from "@flutter-builder/flutter";
import { textDecoration } from "./painting-text-decoration";
import { fontStyle } from "./painting-font-style";
Expand All @@ -10,6 +10,7 @@ export function textStyle(style: ITextStyle): flutter.TextStyle {
const { fontFamily, letterSpacing } = style;
let decoration: flutter.TextDecoration = textDecoration(style.decoration);
const fontWeight: flutter.FontWeight = flutter.FontWeight[style.fontWeight];

return new flutter.TextStyle({
fontSize: rd(style.fontSize),
fontWeight: fontWeight,
Expand All @@ -19,5 +20,6 @@ export function textStyle(style: ITextStyle): flutter.TextStyle {
letterSpacing: length.letterSpacing(style.fontSize, letterSpacing),
height: length.multiple(style.fontSize, style.lineHeight),
decoration: decoration,
shadows: dartui.shadow(style.textShadow),
});
}
3 changes: 2 additions & 1 deletion packages/designto-token/token-text/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nodes } from "@design-sdk/core";
import { RenderedText, TextStyle } from "@reflect-ui/core";
import { RenderedText, TextStyle, TextShadowManifest } from "@reflect-ui/core";
import { keyFromNode } from "../key";

/**
Expand Down Expand Up @@ -47,6 +47,7 @@ export function fromText(node: nodes.ReflectTextNode): RenderedText {
color: node.primaryColor,
lineHeight: node.lineHeight,
letterSpacing: node.letterSpacing,
textShadow: node.shadows as TextShadowManifest[],
}),
...wh,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/reflect-core
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1516,10 +1516,10 @@
resolved "https://registry.yarnpkg.com/@flutter-builder/flutter-material-icons/-/flutter-material-icons-0.0.4.tgz#98fddb0f0295f99c8952c9b214c9755de7c6333e"
integrity sha512-kfzmpVnOJysPBfvrtDuuNJZvpUoO7tGXncRi4WYtoHkmG1ll635D88Ze6OUYhaRLoT7+TXpVl0lk8CDESE/Ykw==

"@flutter-builder/flutter@2.5.0-f13":
version "2.5.0-f13"
resolved "https://registry.yarnpkg.com/@flutter-builder/flutter/-/flutter-2.5.0-f13.tgz#ed7f304a7709111cdb3c9ba98752f353d7cb5bb8"
integrity sha512-LTL4Ng6HORj6Z7MAekr24W/IlDXbAGCFjqpaXX3zwOyqT7vx2XJmgsRqiigFrL3w/juHV4TDWDTuQjZU9USF2Q==
"@flutter-builder/flutter@2.5.0-f16":
version "2.5.0-f16"
resolved "https://registry.yarnpkg.com/@flutter-builder/flutter/-/flutter-2.5.0-f16.tgz#ac524cc35474a2b2d5669c9976d65935694f6244"
integrity sha512-LHT5eOAxqc0bxPjp5lDr+RKQS2fgG2e221LlcdDlDUtuBaIwILAZYWfFQqPQeapqdrpn5+AiXzCZqx8pRX7BHQ==
dependencies:
"@abraham/reflection" "^0.8.0"
"@flutter-builder/flutter-material-icons" "0.0.4"
Expand Down