@forge/react 1.0.0-next.1 → 1.1.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/build/bundle-types.sh +21 -0
- package/package.json +4 -3
- package/src/__test__/styles.test.tsx +112 -0
- package/src/index.ts +2 -0
- package/src/styles/index.ts +174 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @forge/react
|
|
2
2
|
|
|
3
|
+
## 1.1.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 568a4370: Added stylesheet helper methods
|
|
8
|
+
|
|
9
|
+
## 1.0.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [da4c64d]
|
|
14
|
+
- @forge/ui@1.4.0
|
|
15
|
+
|
|
3
16
|
## 1.0.0-next.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#! /bin/bash
|
|
2
|
+
set -exu
|
|
3
|
+
VERSION=27.1.0
|
|
4
|
+
|
|
5
|
+
clean () { rm -rf ./tmp; }
|
|
6
|
+
|
|
7
|
+
cd $(dirname $0)
|
|
8
|
+
rm -rf ./tmp
|
|
9
|
+
rm -rf ../src/types
|
|
10
|
+
|
|
11
|
+
mkdir ./tmp
|
|
12
|
+
trap clean EXIT
|
|
13
|
+
|
|
14
|
+
mkdir ../src/types
|
|
15
|
+
|
|
16
|
+
# Pulls @atlassian/forge-ui-types and copies public types
|
|
17
|
+
(cd ./tmp
|
|
18
|
+
npm pack "@atlassian/forge-ui-types@$VERSION"
|
|
19
|
+
tar -xvf *.tgz
|
|
20
|
+
cp -R "./package/src/public/." "../../src/types/."
|
|
21
|
+
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0-next.0",
|
|
4
4
|
"description": "Forge React reconciler",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "yarn run clean && yarn run compile",
|
|
11
11
|
"clean": "rm -rf ./out && rm -f tsconfig.tsbuildinfo",
|
|
12
|
-
"compile": "tsc -p tsconfig.json"
|
|
12
|
+
"compile": "tsc -p tsconfig.json",
|
|
13
|
+
"pack": "./build/bundle-types.sh"
|
|
13
14
|
},
|
|
14
15
|
"peerDependencies": {
|
|
15
|
-
"@forge/ui": "1.4.0
|
|
16
|
+
"@forge/ui": "1.4.0"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
19
|
"@types/react-reconciler": "^0.28.0",
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {
|
|
2
|
+
active,
|
|
3
|
+
focus,
|
|
4
|
+
gradientStep,
|
|
5
|
+
hover,
|
|
6
|
+
linearGradient,
|
|
7
|
+
radialGradient,
|
|
8
|
+
rgba,
|
|
9
|
+
rotate,
|
|
10
|
+
scale,
|
|
11
|
+
skew,
|
|
12
|
+
StyleSheet,
|
|
13
|
+
translate,
|
|
14
|
+
url
|
|
15
|
+
} from '../styles';
|
|
16
|
+
|
|
17
|
+
describe('StyleSheet', () => {
|
|
18
|
+
it('should create valid basic styles object', () => {
|
|
19
|
+
expect(
|
|
20
|
+
StyleSheet.create({
|
|
21
|
+
container: {
|
|
22
|
+
backgroundColor: '#fff',
|
|
23
|
+
backgroundImage: [
|
|
24
|
+
url('/image.png'),
|
|
25
|
+
linearGradient('90deg', gradientStep('10%', 'red'), gradientStep('30%', 'blue'))
|
|
26
|
+
],
|
|
27
|
+
backgroundSize: ['cover', ['50%', '50%']]
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
).toEqual({
|
|
31
|
+
container: {
|
|
32
|
+
backgroundColor: '#fff',
|
|
33
|
+
backgroundImage: [
|
|
34
|
+
{ method: 'url', value: { path: '/image.png' } },
|
|
35
|
+
{
|
|
36
|
+
method: 'gradient',
|
|
37
|
+
value: {
|
|
38
|
+
colors: [
|
|
39
|
+
{ percent: '10%', value: 'red' },
|
|
40
|
+
{ percent: '30%', value: 'blue' }
|
|
41
|
+
],
|
|
42
|
+
degrees: '90deg',
|
|
43
|
+
type: 'linear'
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
backgroundSize: ['cover', ['50%', '50%']]
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should create valid composed styles object', () => {
|
|
53
|
+
expect(
|
|
54
|
+
StyleSheet.create({
|
|
55
|
+
container: (compose) =>
|
|
56
|
+
compose(
|
|
57
|
+
{
|
|
58
|
+
backgroundColor: 'red',
|
|
59
|
+
backgroundImage: url('https://example.test/image.png'),
|
|
60
|
+
backgroundPosition: ['50px', '50px', '50px', '50px'],
|
|
61
|
+
transform: [
|
|
62
|
+
translate('10px', '10px', '10px'),
|
|
63
|
+
scale('2', '2', '2'),
|
|
64
|
+
rotate('45deg', '45deg', '45deg'),
|
|
65
|
+
skew('45deg', '45deg')
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
active({
|
|
69
|
+
backgroundColor: rgba(0, 0, 255, 1),
|
|
70
|
+
backgroundImage: radialGradient(gradientStep('10%', 'red'), gradientStep('30%', 'blue')),
|
|
71
|
+
backgroundPosition: ['50px', '50px']
|
|
72
|
+
}),
|
|
73
|
+
hover({
|
|
74
|
+
backgroundPosition: 'center',
|
|
75
|
+
backgroundRepeat: 'no-repeat'
|
|
76
|
+
}),
|
|
77
|
+
focus({
|
|
78
|
+
backgroundRepeat: ['repeat', 'repeat']
|
|
79
|
+
})
|
|
80
|
+
)
|
|
81
|
+
})
|
|
82
|
+
).toEqual({
|
|
83
|
+
container: {
|
|
84
|
+
__active: {
|
|
85
|
+
backgroundColor: { method: 'rgba', value: { a: 1, b: 255, g: 0, r: 0 } },
|
|
86
|
+
backgroundImage: {
|
|
87
|
+
method: 'gradient',
|
|
88
|
+
value: {
|
|
89
|
+
colors: [
|
|
90
|
+
{ percent: '10%', value: 'red' },
|
|
91
|
+
{ percent: '30%', value: 'blue' }
|
|
92
|
+
],
|
|
93
|
+
type: 'radial'
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
backgroundPosition: ['50px', '50px']
|
|
97
|
+
},
|
|
98
|
+
__focus: { backgroundRepeat: ['repeat', 'repeat'] },
|
|
99
|
+
__hover: { backgroundPosition: 'center', backgroundRepeat: 'no-repeat' },
|
|
100
|
+
backgroundColor: 'red',
|
|
101
|
+
backgroundImage: { method: 'url', value: { path: 'https://example.test/image.png' } },
|
|
102
|
+
backgroundPosition: ['50px', '50px', '50px', '50px'],
|
|
103
|
+
transform: [
|
|
104
|
+
{ method: 'translate', value: { x: '10px', y: '10px', z: '10px' } },
|
|
105
|
+
{ method: 'scale', value: { x: '2', y: '2', z: '2' } },
|
|
106
|
+
{ method: 'rotate', value: { x: '45deg', y: '45deg', z: '45deg' } },
|
|
107
|
+
{ method: 'skew', value: { x: '45deg', y: '45deg' } }
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AllowedPrimitives,
|
|
3
|
+
Definitions,
|
|
4
|
+
GradientValue,
|
|
5
|
+
RGBAColorValue,
|
|
6
|
+
ShadowValue,
|
|
7
|
+
TransformValue,
|
|
8
|
+
ColorType,
|
|
9
|
+
URLValue
|
|
10
|
+
} from '../types';
|
|
11
|
+
|
|
12
|
+
export interface PreDefinitions {
|
|
13
|
+
[key: string]: AllowedPrimitives | ComposeProvider;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type Compose = (...primitiveObjects: AllowedPrimitives[]) => AllowedPrimitives;
|
|
17
|
+
export type ComposeProvider = (compose: Compose) => AllowedPrimitives;
|
|
18
|
+
|
|
19
|
+
export const StyleSheet = {
|
|
20
|
+
create(definitions: PreDefinitions): Definitions {
|
|
21
|
+
const stylesheet: Definitions = {};
|
|
22
|
+
|
|
23
|
+
for (const key in definitions) {
|
|
24
|
+
const definition = definitions[key];
|
|
25
|
+
if (typeof definition === 'function') {
|
|
26
|
+
const compose = (...primitivesDefinitions: AllowedPrimitives[]): AllowedPrimitives => {
|
|
27
|
+
return primitivesDefinitions.reduce((acc, primitives) => {
|
|
28
|
+
return { ...acc, ...primitives };
|
|
29
|
+
}, {});
|
|
30
|
+
};
|
|
31
|
+
stylesheet[key] = definition(compose);
|
|
32
|
+
} else {
|
|
33
|
+
stylesheet[key] = definition;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return stylesheet;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const rgba = (r: number, g: number, b: number, a: number): RGBAColorValue => {
|
|
41
|
+
return {
|
|
42
|
+
method: 'rgba',
|
|
43
|
+
value: {
|
|
44
|
+
r,
|
|
45
|
+
g,
|
|
46
|
+
b,
|
|
47
|
+
a
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const rgb = (r: number, g: number, b: number): RGBAColorValue => {
|
|
53
|
+
return {
|
|
54
|
+
method: 'rgb',
|
|
55
|
+
value: {
|
|
56
|
+
r,
|
|
57
|
+
g,
|
|
58
|
+
b
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export function shadow(offsets: string, color: string | RGBAColorValue): ShadowValue {
|
|
64
|
+
return {
|
|
65
|
+
method: 'shadow',
|
|
66
|
+
value: {
|
|
67
|
+
offsets,
|
|
68
|
+
color
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface GradientStep {
|
|
74
|
+
percent: string;
|
|
75
|
+
value: ColorType;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function gradientStep(percent: string, value: ColorType): GradientStep {
|
|
79
|
+
return {
|
|
80
|
+
percent,
|
|
81
|
+
value
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function linearGradient(degrees: string, ...steps: GradientStep[]): GradientValue {
|
|
86
|
+
return {
|
|
87
|
+
method: 'gradient',
|
|
88
|
+
value: {
|
|
89
|
+
type: 'linear',
|
|
90
|
+
colors: steps,
|
|
91
|
+
degrees
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function radialGradient(...steps: GradientStep[]): GradientValue {
|
|
97
|
+
return {
|
|
98
|
+
method: 'gradient',
|
|
99
|
+
value: {
|
|
100
|
+
type: 'radial',
|
|
101
|
+
colors: steps
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function translate(x?: string, y?: string, z?: string): TransformValue {
|
|
107
|
+
return {
|
|
108
|
+
method: 'translate',
|
|
109
|
+
value: {
|
|
110
|
+
x,
|
|
111
|
+
y,
|
|
112
|
+
z
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function scale(x?: string, y?: string, z?: string): TransformValue {
|
|
118
|
+
return {
|
|
119
|
+
method: 'scale',
|
|
120
|
+
value: {
|
|
121
|
+
x,
|
|
122
|
+
y,
|
|
123
|
+
z
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function rotate(x?: string, y?: string, z?: string): TransformValue {
|
|
129
|
+
return {
|
|
130
|
+
method: 'rotate',
|
|
131
|
+
value: {
|
|
132
|
+
x,
|
|
133
|
+
y,
|
|
134
|
+
z
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function skew(x?: string, y?: string): TransformValue {
|
|
140
|
+
return {
|
|
141
|
+
method: 'skew',
|
|
142
|
+
value: {
|
|
143
|
+
x,
|
|
144
|
+
y
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function url(path: string): URLValue {
|
|
150
|
+
return {
|
|
151
|
+
method: 'url',
|
|
152
|
+
value: {
|
|
153
|
+
path
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function focus(primitives: AllowedPrimitives): AllowedPrimitives {
|
|
159
|
+
return {
|
|
160
|
+
__focus: primitives
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function hover(primitives: AllowedPrimitives): AllowedPrimitives {
|
|
165
|
+
return {
|
|
166
|
+
__hover: primitives
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function active(primitives: AllowedPrimitives): AllowedPrimitives {
|
|
171
|
+
return {
|
|
172
|
+
__active: primitives
|
|
173
|
+
};
|
|
174
|
+
}
|