@gitlab/ui 65.0.1 → 65.1.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 +7 -0
- package/dist/components/base/form/form_fields/validators.js +33 -1
- package/dist/tokens/css/tokens.css +1 -1
- package/dist/tokens/css/tokens.dark.css +1 -1
- package/dist/tokens/js/tokens.dark.js +1 -1
- package/dist/tokens/js/tokens.js +1 -1
- package/dist/tokens/scss/_tokens.dark.scss +1 -1
- package/dist/tokens/scss/_tokens.scss +1 -1
- package/package.json +3 -3
- package/src/components/base/form/form_fields/validators.js +33 -0
- package/src/components/base/form/form_fields/validators.spec.js +28 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [65.1.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v65.0.1...v65.1.0) (2023-08-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **GlFormFields:** Add validator for emojis ([7f5b9aa](https://gitlab.com/gitlab-org/gitlab-ui/commit/7f5b9aa195b3a62a83b5b395aec2e49d08b87bcb))
|
|
7
|
+
|
|
1
8
|
## [65.0.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v65.0.0...v65.0.1) (2023-08-05)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import emojiRegex from 'emoji-regex';
|
|
2
|
+
|
|
3
|
+
const EMOJI_REGEX = emojiRegex();
|
|
4
|
+
|
|
1
5
|
// This contains core validating behavior and **should not** contain
|
|
2
6
|
// domain-specific validations.
|
|
3
7
|
//
|
|
@@ -11,6 +15,34 @@
|
|
|
11
15
|
// export const projectPathIsUnique = ...
|
|
12
16
|
// ```
|
|
13
17
|
const factory = (failMessage, isValid) => val => !isValid(val) ? failMessage : '';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Validator function to check if a string is present and non-empty.
|
|
21
|
+
*
|
|
22
|
+
* Returns an empty string if the input contains a valid string.
|
|
23
|
+
*
|
|
24
|
+
* Returns `failMessage` if the input string is empty, null, or undefined.
|
|
25
|
+
* @param {string} failMessage - The error message to be returned when validation fails.
|
|
26
|
+
* @returns {Function} A validation function that returns either `failMessage` or empty string.
|
|
27
|
+
*/
|
|
14
28
|
const required = failMessage => factory(failMessage, val => val !== '' && val !== null && val !== undefined);
|
|
15
29
|
|
|
16
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Validator function to check if a string contains any emojis.
|
|
32
|
+
*
|
|
33
|
+
* Returns an empty string if the input is empty, null, or undefined, or if no emoji is present.
|
|
34
|
+
*
|
|
35
|
+
* Returns `failMessage` if the input string contains at least one emoji.
|
|
36
|
+
* @param {string} failMessage - The error message to be returned when validation fails.
|
|
37
|
+
* @returns {Function} A validation function that returns either `failMessage` or empty string.
|
|
38
|
+
*/
|
|
39
|
+
const noEmojis = failMessage => factory(failMessage, val => {
|
|
40
|
+
var _val$match$length, _val$match;
|
|
41
|
+
if (!val || typeof val !== 'string') {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
const resultsLength = (_val$match$length = (_val$match = val.match(EMOJI_REGEX)) === null || _val$match === void 0 ? void 0 : _val$match.length) !== null && _val$match$length !== void 0 ? _val$match$length : 0;
|
|
45
|
+
return resultsLength < 1;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export { factory, noEmojis, required };
|
package/dist/tokens/js/tokens.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitlab/ui",
|
|
3
|
-
"version": "65.0
|
|
3
|
+
"version": "65.1.0",
|
|
4
4
|
"description": "GitLab UI Components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@gitlab/eslint-plugin": "19.0.0",
|
|
92
92
|
"@gitlab/fonts": "^1.2.0",
|
|
93
93
|
"@gitlab/stylelint-config": "4.1.0",
|
|
94
|
-
"@gitlab/svgs": "3.
|
|
94
|
+
"@gitlab/svgs": "3.59.0",
|
|
95
95
|
"@rollup/plugin-commonjs": "^11.1.0",
|
|
96
96
|
"@rollup/plugin-node-resolve": "^7.1.3",
|
|
97
97
|
"@rollup/plugin-replace": "^2.3.2",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"babel-loader": "^8.0.5",
|
|
119
119
|
"babel-plugin-require-context-hook": "^1.0.0",
|
|
120
120
|
"bootstrap": "4.6.2",
|
|
121
|
-
"cypress": "12.17.
|
|
121
|
+
"cypress": "12.17.3",
|
|
122
122
|
"dompurify": "^2.4.7",
|
|
123
123
|
"emoji-regex": "^10.0.0",
|
|
124
124
|
"eslint": "8.46.0",
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import emojiRegex from 'emoji-regex';
|
|
2
|
+
|
|
3
|
+
const EMOJI_REGEX = emojiRegex();
|
|
4
|
+
|
|
1
5
|
// This contains core validating behavior and **should not** contain
|
|
2
6
|
// domain-specific validations.
|
|
3
7
|
//
|
|
@@ -12,5 +16,34 @@
|
|
|
12
16
|
// ```
|
|
13
17
|
export const factory = (failMessage, isValid) => (val) => !isValid(val) ? failMessage : '';
|
|
14
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Validator function to check if a string is present and non-empty.
|
|
21
|
+
*
|
|
22
|
+
* Returns an empty string if the input contains a valid string.
|
|
23
|
+
*
|
|
24
|
+
* Returns `failMessage` if the input string is empty, null, or undefined.
|
|
25
|
+
* @param {string} failMessage - The error message to be returned when validation fails.
|
|
26
|
+
* @returns {Function} A validation function that returns either `failMessage` or empty string.
|
|
27
|
+
*/
|
|
15
28
|
export const required = (failMessage) =>
|
|
16
29
|
factory(failMessage, (val) => val !== '' && val !== null && val !== undefined);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Validator function to check if a string contains any emojis.
|
|
33
|
+
*
|
|
34
|
+
* Returns an empty string if the input is empty, null, or undefined, or if no emoji is present.
|
|
35
|
+
*
|
|
36
|
+
* Returns `failMessage` if the input string contains at least one emoji.
|
|
37
|
+
* @param {string} failMessage - The error message to be returned when validation fails.
|
|
38
|
+
* @returns {Function} A validation function that returns either `failMessage` or empty string.
|
|
39
|
+
*/
|
|
40
|
+
export const noEmojis = (failMessage) =>
|
|
41
|
+
factory(failMessage, (val) => {
|
|
42
|
+
if (!val || typeof val !== 'string') {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const resultsLength = val.match(EMOJI_REGEX)?.length ?? 0;
|
|
47
|
+
|
|
48
|
+
return resultsLength < 1;
|
|
49
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { required } from './validators';
|
|
1
|
+
import { noEmojis, required } from './validators';
|
|
2
2
|
|
|
3
3
|
const TEST_FAIL_MESSAGE = 'Yo test failed!';
|
|
4
4
|
|
|
@@ -26,4 +26,31 @@ describe('components/base/form/form_fields/validators', () => {
|
|
|
26
26
|
expect(validator(input)).toBe(output);
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
|
+
|
|
30
|
+
describe('noEmojis', () => {
|
|
31
|
+
let validator;
|
|
32
|
+
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
validator = noEmojis(TEST_FAIL_MESSAGE);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it.each`
|
|
38
|
+
input | output
|
|
39
|
+
${'123🐱'} | ${TEST_FAIL_MESSAGE}
|
|
40
|
+
${'0 🍩'} | ${TEST_FAIL_MESSAGE}
|
|
41
|
+
${'🐟'} | ${TEST_FAIL_MESSAGE}
|
|
42
|
+
${''} | ${''}
|
|
43
|
+
${null} | ${''}
|
|
44
|
+
${undefined} | ${''}
|
|
45
|
+
${'123'} | ${''}
|
|
46
|
+
${'0'} | ${''}
|
|
47
|
+
${{}} | ${''}
|
|
48
|
+
${0} | ${''}
|
|
49
|
+
${1} | ${''}
|
|
50
|
+
${true} | ${''}
|
|
51
|
+
${false} | ${''}
|
|
52
|
+
`('with $input, returns $output', ({ input, output }) => {
|
|
53
|
+
expect(validator(input)).toBe(output);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
29
56
|
});
|