-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add space-separated string support for fontVariant (#34641)
Summary: This updates `fontVariant` to support space-separated string values, i.e., `'small-caps common-ligatures'`, thus aligning it with the [CSS Fonts Module Level 4](https://drafts.csswg.org/css-fonts/#font-variant-prop) specification as requested on #34425. This also adds unit tests to the `processFontVariant` function ensuring the style processing works as expected. ## Changelog [General] [Added] - Add space-separated string support for fontVariant Pull Request resolved: #34641 Test Plan: This can be tested either through `processFontVariant-tests` or by using the following code: ```js <Text style={{ fontVariant: 'small-caps common-ligatures', }} /> ``` Reviewed By: javache Differential Revision: D39423317 Pulled By: cipolleschi fbshipit-source-id: ad971addb423ed338e178528a11fe9d456c03e6e
- Loading branch information
1 parent
34fafb2
commit 09d4207
Showing
4 changed files
with
111 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @emails oncall+react_native | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const processFontVariant = require('../processFontVariant'); | ||
|
||
describe('processFontVariant', () => { | ||
it('should accept arrays', () => { | ||
expect(processFontVariant([])).toEqual([]); | ||
expect(processFontVariant(['oldstyle-nums'])).toEqual(['oldstyle-nums']); | ||
expect(processFontVariant(['proportional-nums', 'lining-nums'])).toEqual([ | ||
'proportional-nums', | ||
'lining-nums', | ||
]); | ||
}); | ||
|
||
it('should accept string values', () => { | ||
expect(processFontVariant('oldstyle-nums')).toEqual(['oldstyle-nums']); | ||
expect(processFontVariant('lining-nums ')).toEqual(['lining-nums']); | ||
expect(processFontVariant(' tabular-nums')).toEqual(['tabular-nums']); | ||
}); | ||
|
||
it('should accept string with multiple values', () => { | ||
expect(processFontVariant('oldstyle-nums lining-nums')).toEqual([ | ||
'oldstyle-nums', | ||
'lining-nums', | ||
]); | ||
expect( | ||
processFontVariant('proportional-nums oldstyle-nums lining-nums'), | ||
).toEqual(['proportional-nums', 'oldstyle-nums', 'lining-nums']); | ||
expect( | ||
processFontVariant( | ||
' small-caps proportional-nums oldstyle-nums lining-nums', | ||
), | ||
).toEqual([ | ||
'small-caps', | ||
'proportional-nums', | ||
'oldstyle-nums', | ||
'lining-nums', | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {____FontVariantArray_Internal} from './StyleSheetTypes'; | ||
|
||
function processFontVariant( | ||
fontVariant: ____FontVariantArray_Internal | string, | ||
): ?____FontVariantArray_Internal { | ||
if (Array.isArray(fontVariant)) { | ||
return fontVariant; | ||
} | ||
|
||
// $FlowFixMe[incompatible-type] | ||
const match: ?____FontVariantArray_Internal = fontVariant | ||
.split(' ') | ||
.filter(Boolean); | ||
|
||
return match; | ||
} | ||
|
||
module.exports = processFontVariant; |