|
| 1 | +import rn from 'react-native'; |
1 | 2 | import { create } from '../'; |
2 | 3 |
|
3 | 4 | describe(`transform utilities`, () => { |
@@ -207,12 +208,6 @@ describe(`transform utilities`, () => { |
207 | 208 | // not configged |
208 | 209 | [`translate-x-81`, { transform: [{ translateX: (81 / 4) * 16 }] }], |
209 | 210 | [`translate-y-81`, { transform: [{ translateY: (81 / 4) * 16 }] }], |
210 | | - |
211 | | - // unsupported |
212 | | - [`translate-x-full`, {}], |
213 | | - [`translate-y-full`, {}], |
214 | | - [`translate-x-1/2`, {}], |
215 | | - [`translate-y-1/2`, {}], |
216 | 211 | ]; |
217 | 212 |
|
218 | 213 | test.each(cases)(`tw\`%s\` -> %s`, (utility, expected) => { |
@@ -246,6 +241,54 @@ describe(`transform utilities`, () => { |
246 | 241 | transform: [{ translateY: 16 }], |
247 | 242 | }); |
248 | 243 | }); |
| 244 | + |
| 245 | + test(`translate w/percentage values`, () => { |
| 246 | + rn.Platform.constants.reactNativeVersion = { |
| 247 | + major: 0, |
| 248 | + minor: 75, |
| 249 | + patch: 0, |
| 250 | + }; |
| 251 | + |
| 252 | + expect(tw.style(`translate-x-full`)).toMatchObject({ |
| 253 | + transform: [{ translateX: `100%` }], |
| 254 | + }); |
| 255 | + expect(tw.style(`translate-y-full`)).toMatchObject({ |
| 256 | + transform: [{ translateY: `100%` }], |
| 257 | + }); |
| 258 | + expect(tw.style(`translate-x-1/2`)).toMatchObject({ |
| 259 | + transform: [{ translateX: `50%` }], |
| 260 | + }); |
| 261 | + expect(tw.style(`translate-y-1/2`)).toMatchObject({ |
| 262 | + transform: [{ translateY: `50%` }], |
| 263 | + }); |
| 264 | + expect(tw.style(`translate-x-[10%]`)).toMatchObject({ |
| 265 | + transform: [{ translateX: `10%` }], |
| 266 | + }); |
| 267 | + expect(tw.style(`translate-y-[10%]`)).toMatchObject({ |
| 268 | + transform: [{ translateY: `10%` }], |
| 269 | + }); |
| 270 | + expect(tw.style(`translate-x-1/5`)).toMatchObject({ |
| 271 | + transform: [{ translateX: `20%` }], |
| 272 | + }); |
| 273 | + expect(tw.style(`translate-y-1/5`)).toMatchObject({ |
| 274 | + transform: [{ translateY: `20%` }], |
| 275 | + }); |
| 276 | + |
| 277 | + rn.Platform.constants.reactNativeVersion = { |
| 278 | + major: 0, |
| 279 | + minor: 74, |
| 280 | + patch: 0, |
| 281 | + }; |
| 282 | + |
| 283 | + expect(tw.style(`translate-x-full`)).toMatchObject({}); |
| 284 | + expect(tw.style(`translate-y-full`)).toMatchObject({}); |
| 285 | + expect(tw.style(`translate-x-1/2`)).toMatchObject({}); |
| 286 | + expect(tw.style(`translate-y-1/2`)).toMatchObject({}); |
| 287 | + expect(tw.style(`translate-x-[10%]`)).toMatchObject({}); |
| 288 | + expect(tw.style(`translate-y-[10%]`)).toMatchObject({}); |
| 289 | + expect(tw.style(`translate-x-1/5`)).toMatchObject({}); |
| 290 | + expect(tw.style(`translate-y-1/5`)).toMatchObject({}); |
| 291 | + }); |
249 | 292 | }); |
250 | 293 |
|
251 | 294 | test(`combine multiple transform utilities `, () => { |
@@ -276,4 +319,59 @@ describe(`transform utilities`, () => { |
276 | 319 | ), |
277 | 320 | ).toMatchObject({ transform: [] }); |
278 | 321 | }); |
| 322 | + |
| 323 | + describe(`origin`, () => { |
| 324 | + const cases: Array< |
| 325 | + [string, Record<'transformOrigin', string> | Record<string, never>] |
| 326 | + > = [ |
| 327 | + [`origin-center`, { transformOrigin: `center` }], |
| 328 | + [`origin-top`, { transformOrigin: `top` }], |
| 329 | + [`origin-top-right`, { transformOrigin: `top right` }], |
| 330 | + [`origin-right`, { transformOrigin: `right` }], |
| 331 | + [`origin-bottom-right`, { transformOrigin: `bottom right` }], |
| 332 | + [`origin-bottom`, { transformOrigin: `bottom` }], |
| 333 | + [`origin-bottom-left`, { transformOrigin: `bottom left` }], |
| 334 | + [`origin-left`, { transformOrigin: `left` }], |
| 335 | + [`origin-top-left`, { transformOrigin: `top left` }], |
| 336 | + |
| 337 | + // arbitrary |
| 338 | + [`origin-[top]`, { transformOrigin: `top` }], |
| 339 | + [`origin-[10%]`, { transformOrigin: `10%` }], |
| 340 | + [`origin-[10px]`, { transformOrigin: `10px` }], |
| 341 | + [`origin-[left_top]`, { transformOrigin: `left top` }], |
| 342 | + [`origin-[bottom_right]`, { transformOrigin: `bottom right` }], |
| 343 | + [`origin-[center_center]`, { transformOrigin: `center center` }], |
| 344 | + [`origin-[center_10%]`, { transformOrigin: `center 10%` }], |
| 345 | + [`origin-[10px_center]`, { transformOrigin: `10px center` }], |
| 346 | + [`origin-[10px_10%]`, { transformOrigin: `10px 10%` }], |
| 347 | + [`origin-[-10%_20%_10px]`, { transformOrigin: `-10% 20% 10px` }], |
| 348 | + [`origin-[-10px_-10px_-10px]`, { transformOrigin: `-10px -10px -10px` }], |
| 349 | + [`origin-[left_top_10px]`, { transformOrigin: `left top 10px` }], |
| 350 | + |
| 351 | + // invalid |
| 352 | + [`origin-[left_left]`, {}], |
| 353 | + [`origin-[top_top]`, {}], |
| 354 | + [`origin-[top_left_10%]`, {}], |
| 355 | + ]; |
| 356 | + |
| 357 | + test.each(cases)(`tw\`%s\` -> %s`, (utility, expected) => { |
| 358 | + expect(tw.style(utility)).toMatchObject(expected); |
| 359 | + }); |
| 360 | + |
| 361 | + test(`origin w/extended theme`, () => { |
| 362 | + tw = create({ |
| 363 | + theme: { |
| 364 | + extend: { |
| 365 | + transformOrigin: { |
| 366 | + custom: `33% 75% 10px`, |
| 367 | + }, |
| 368 | + }, |
| 369 | + }, |
| 370 | + }); |
| 371 | + |
| 372 | + expect(tw.style(`origin-custom`)).toMatchObject({ |
| 373 | + transformOrigin: `33% 75% 10px`, |
| 374 | + }); |
| 375 | + }); |
| 376 | + }); |
279 | 377 | }); |
0 commit comments