@digigov/react-core 0.22.0 → 0.23.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 +9 -1
- package/Nav/__snapshots__/index.test.tsx.snap +4 -4
- package/Nav/index.js +1 -1
- package/NavList/__snapshots__/index.test.tsx.snap +4 -4
- package/NavList/index.d.ts +1 -6
- package/NavList/index.js +2 -4
- package/NavListItem/__snapshots__/index.test.tsx.snap +2 -2
- package/NavListItem/index.d.ts +1 -6
- package/NavListItem/index.js +2 -4
- package/NavListItemButton/__snapshots__/index.test.tsx.snap +9 -9
- package/NavListItemButton/index.js +1 -1
- package/NavListItemLink/__snapshots__/index.test.tsx.snap +15 -24
- package/NavListItemLink/index.js +2 -3
- package/NavMenu/__snapshots__/index.test.tsx.snap +2 -2
- package/NavMenu/index.js +1 -1
- package/NavMenuContainer/index.js +1 -3
- package/NavMenuContainerContent/index.js +1 -3
- package/NavMenuContainerContentList/__snapshots__/index.test.tsx.snap +2 -2
- package/NavMenuContainerContentList/index.d.ts +1 -6
- package/NavMenuContainerContentList/index.js +2 -4
- package/NavMenuContainerContentListItem/__snapshots__/index.test.tsx.snap +2 -2
- package/NavMenuContainerContentListItem/index.js +1 -1
- package/NavMenuContainerTitle/index.d.ts +1 -6
- package/NavMenuContainerTitle/index.js +3 -5
- package/SingleCharacterInputContainer/__snapshots__/index.test.tsx.snap +16 -0
- package/SingleCharacterInputContainer/index.d.ts +11 -0
- package/SingleCharacterInputContainer/index.js +40 -0
- package/SingleCharacterInputContainer/index.test.d.ts +1 -0
- package/SingleCharacterInputContainer/index.test.js +15 -0
- package/SingleCharacterInputItem/__snapshots__/index.test.tsx.snap +173 -0
- package/SingleCharacterInputItem/index.d.ts +32 -0
- package/SingleCharacterInputItem/index.js +50 -0
- package/SingleCharacterInputItem/index.test.d.ts +1 -0
- package/SingleCharacterInputItem/index.test.js +68 -0
- package/es/Nav/__snapshots__/index.test.tsx.snap +4 -4
- package/es/Nav/index.js +1 -1
- package/es/NavList/__snapshots__/index.test.tsx.snap +4 -4
- package/es/NavList/index.js +2 -4
- package/es/NavListItem/__snapshots__/index.test.tsx.snap +2 -2
- package/es/NavListItem/index.js +2 -4
- package/es/NavListItemButton/__snapshots__/index.test.tsx.snap +9 -9
- package/es/NavListItemButton/index.js +1 -1
- package/es/NavListItemLink/__snapshots__/index.test.tsx.snap +15 -24
- package/es/NavListItemLink/index.js +2 -3
- package/es/NavMenu/__snapshots__/index.test.tsx.snap +2 -2
- package/es/NavMenu/index.js +1 -1
- package/es/NavMenuContainer/index.js +1 -2
- package/es/NavMenuContainerContent/index.js +1 -2
- package/es/NavMenuContainerContentList/__snapshots__/index.test.tsx.snap +2 -2
- package/es/NavMenuContainerContentList/index.js +2 -4
- package/es/NavMenuContainerContentListItem/__snapshots__/index.test.tsx.snap +2 -2
- package/es/NavMenuContainerContentListItem/index.js +1 -1
- package/es/NavMenuContainerTitle/index.js +3 -5
- package/es/SingleCharacterInputContainer/__snapshots__/index.test.tsx.snap +16 -0
- package/es/SingleCharacterInputContainer/index.js +24 -0
- package/es/SingleCharacterInputContainer/index.test.js +9 -0
- package/es/SingleCharacterInputItem/__snapshots__/index.test.tsx.snap +173 -0
- package/es/SingleCharacterInputItem/index.js +34 -0
- package/es/SingleCharacterInputItem/index.test.js +62 -0
- package/es/index.js +2 -0
- package/es/registry.js +4 -0
- package/esm/Nav/__snapshots__/index.test.tsx.snap +4 -4
- package/esm/Nav/index.js +1 -1
- package/esm/NavList/__snapshots__/index.test.tsx.snap +4 -4
- package/esm/NavList/index.js +2 -4
- package/esm/NavListItem/__snapshots__/index.test.tsx.snap +2 -2
- package/esm/NavListItem/index.js +2 -4
- package/esm/NavListItemButton/__snapshots__/index.test.tsx.snap +9 -9
- package/esm/NavListItemButton/index.js +1 -1
- package/esm/NavListItemLink/__snapshots__/index.test.tsx.snap +15 -24
- package/esm/NavListItemLink/index.js +2 -3
- package/esm/NavMenu/__snapshots__/index.test.tsx.snap +2 -2
- package/esm/NavMenu/index.js +1 -1
- package/esm/NavMenuContainer/index.js +1 -2
- package/esm/NavMenuContainerContent/index.js +1 -2
- package/esm/NavMenuContainerContentList/__snapshots__/index.test.tsx.snap +2 -2
- package/esm/NavMenuContainerContentList/index.js +2 -4
- package/esm/NavMenuContainerContentListItem/__snapshots__/index.test.tsx.snap +2 -2
- package/esm/NavMenuContainerContentListItem/index.js +1 -1
- package/esm/NavMenuContainerTitle/index.js +3 -5
- package/esm/SingleCharacterInputContainer/__snapshots__/index.test.tsx.snap +16 -0
- package/esm/SingleCharacterInputContainer/index.js +24 -0
- package/esm/SingleCharacterInputContainer/index.test.js +9 -0
- package/esm/SingleCharacterInputItem/__snapshots__/index.test.tsx.snap +173 -0
- package/esm/SingleCharacterInputItem/index.js +34 -0
- package/esm/SingleCharacterInputItem/index.test.js +62 -0
- package/esm/index.js +3 -1
- package/esm/registry.js +4 -0
- package/index.d.ts +2 -0
- package/index.js +26 -0
- package/package.json +2 -2
- package/registry.d.ts +2 -0
- package/registry.js +6 -0
- package/src/Nav/__snapshots__/index.test.tsx.snap +4 -4
- package/src/Nav/index.tsx +7 -6
- package/src/NavList/__snapshots__/index.test.tsx.snap +4 -4
- package/src/NavList/index.tsx +3 -13
- package/src/NavListItem/__snapshots__/index.test.tsx.snap +2 -2
- package/src/NavListItem/index.tsx +3 -13
- package/src/NavListItemButton/__snapshots__/index.test.tsx.snap +9 -9
- package/src/NavListItemButton/index.tsx +2 -2
- package/src/NavListItemLink/__snapshots__/index.test.tsx.snap +15 -24
- package/src/NavListItemLink/index.tsx +3 -3
- package/src/NavMenu/__snapshots__/index.test.tsx.snap +2 -2
- package/src/NavMenu/index.tsx +4 -3
- package/src/NavMenuContainer/index.tsx +1 -2
- package/src/NavMenuContainerContent/index.tsx +1 -2
- package/src/NavMenuContainerContentList/__snapshots__/index.test.tsx.snap +2 -2
- package/src/NavMenuContainerContentList/index.tsx +3 -13
- package/src/NavMenuContainerContentListItem/__snapshots__/index.test.tsx.snap +2 -2
- package/src/NavMenuContainerContentListItem/index.tsx +1 -1
- package/src/NavMenuContainerTitle/index.tsx +4 -14
- package/src/SingleCharacterInputContainer/__snapshots__/index.test.tsx.snap +16 -0
- package/src/SingleCharacterInputContainer/index.test.tsx +10 -0
- package/src/SingleCharacterInputContainer/index.tsx +32 -0
- package/src/SingleCharacterInputItem/__snapshots__/index.test.tsx.snap +173 -0
- package/src/SingleCharacterInputItem/index.test.tsx +45 -0
- package/src/SingleCharacterInputItem/index.tsx +63 -0
- package/src/index.ts +2 -0
- package/src/registry.js +4 -0
|
@@ -5,17 +5,14 @@ exports[`renders the NavListItemLink with active=false 1`] = `
|
|
|
5
5
|
active={false}
|
|
6
6
|
>
|
|
7
7
|
<ForwardRef(LinkBase)
|
|
8
|
-
className="govgr-
|
|
9
|
-
href="#"
|
|
8
|
+
className="govgr-nav__list-item-link"
|
|
10
9
|
>
|
|
11
10
|
<ForwardRef(Base)
|
|
12
11
|
as="a"
|
|
13
|
-
className="govgr-
|
|
14
|
-
href="#"
|
|
12
|
+
className="govgr-nav__list-item-link govgr-link"
|
|
15
13
|
>
|
|
16
14
|
<a
|
|
17
|
-
className="govgr-
|
|
18
|
-
href="#"
|
|
15
|
+
className="govgr-nav__list-item-link govgr-link"
|
|
19
16
|
>
|
|
20
17
|
hello
|
|
21
18
|
</a>
|
|
@@ -29,17 +26,14 @@ exports[`renders the NavListItemLink with active=true 1`] = `
|
|
|
29
26
|
active={true}
|
|
30
27
|
>
|
|
31
28
|
<ForwardRef(LinkBase)
|
|
32
|
-
className="govgr-
|
|
33
|
-
href="#"
|
|
29
|
+
className="govgr-nav__list-item-link--active govgr-nav__list-item-link"
|
|
34
30
|
>
|
|
35
31
|
<ForwardRef(Base)
|
|
36
32
|
as="a"
|
|
37
|
-
className="govgr-
|
|
38
|
-
href="#"
|
|
33
|
+
className="govgr-nav__list-item-link--active govgr-nav__list-item-link govgr-link"
|
|
39
34
|
>
|
|
40
35
|
<a
|
|
41
|
-
className="govgr-
|
|
42
|
-
href="#"
|
|
36
|
+
className="govgr-nav__list-item-link--active govgr-nav__list-item-link govgr-link"
|
|
43
37
|
>
|
|
44
38
|
hello
|
|
45
39
|
</a>
|
|
@@ -54,16 +48,16 @@ exports[`renders the NavListItemLink with href and active=false 1`] = `
|
|
|
54
48
|
href="/"
|
|
55
49
|
>
|
|
56
50
|
<ForwardRef(LinkBase)
|
|
57
|
-
className="govgr-
|
|
51
|
+
className="govgr-nav__list-item-link"
|
|
58
52
|
href="/"
|
|
59
53
|
>
|
|
60
54
|
<ForwardRef(Base)
|
|
61
55
|
as="a"
|
|
62
|
-
className="govgr-
|
|
56
|
+
className="govgr-nav__list-item-link govgr-link"
|
|
63
57
|
href="/"
|
|
64
58
|
>
|
|
65
59
|
<a
|
|
66
|
-
className="govgr-
|
|
60
|
+
className="govgr-nav__list-item-link govgr-link"
|
|
67
61
|
href="/"
|
|
68
62
|
>
|
|
69
63
|
hello
|
|
@@ -79,16 +73,16 @@ exports[`renders the NavListItemLink with href and active=true 1`] = `
|
|
|
79
73
|
href="/"
|
|
80
74
|
>
|
|
81
75
|
<ForwardRef(LinkBase)
|
|
82
|
-
className="govgr-
|
|
76
|
+
className="govgr-nav__list-item-link"
|
|
83
77
|
href="/"
|
|
84
78
|
>
|
|
85
79
|
<ForwardRef(Base)
|
|
86
80
|
as="a"
|
|
87
|
-
className="govgr-
|
|
81
|
+
className="govgr-nav__list-item-link govgr-link"
|
|
88
82
|
href="/"
|
|
89
83
|
>
|
|
90
84
|
<a
|
|
91
|
-
className="govgr-
|
|
85
|
+
className="govgr-nav__list-item-link govgr-link"
|
|
92
86
|
href="/"
|
|
93
87
|
>
|
|
94
88
|
hello
|
|
@@ -101,17 +95,14 @@ exports[`renders the NavListItemLink with href and active=true 1`] = `
|
|
|
101
95
|
exports[`renders the NavListItemLink with no props 1`] = `
|
|
102
96
|
<ForwardRef(NavListItemLink)>
|
|
103
97
|
<ForwardRef(LinkBase)
|
|
104
|
-
className="govgr-
|
|
105
|
-
href="#"
|
|
98
|
+
className="govgr-nav__list-item-link"
|
|
106
99
|
>
|
|
107
100
|
<ForwardRef(Base)
|
|
108
101
|
as="a"
|
|
109
|
-
className="govgr-
|
|
110
|
-
href="#"
|
|
102
|
+
className="govgr-nav__list-item-link govgr-link"
|
|
111
103
|
>
|
|
112
104
|
<a
|
|
113
|
-
className="govgr-
|
|
114
|
-
href="#"
|
|
105
|
+
className="govgr-nav__list-item-link govgr-link"
|
|
115
106
|
>
|
|
116
107
|
hello
|
|
117
108
|
</a>
|
|
@@ -23,7 +23,7 @@ export const NavListItemLink = React.forwardRef<
|
|
|
23
23
|
HTMLAnchorElement,
|
|
24
24
|
NavListItemLinkProps
|
|
25
25
|
>(function NavListItemLink(
|
|
26
|
-
{ active, href
|
|
26
|
+
{ active, href, className, children, ...props },
|
|
27
27
|
ref
|
|
28
28
|
) {
|
|
29
29
|
return (
|
|
@@ -31,8 +31,8 @@ export const NavListItemLink = React.forwardRef<
|
|
|
31
31
|
href={href}
|
|
32
32
|
ref={ref}
|
|
33
33
|
className={clsx(className, {
|
|
34
|
-
'govgr-
|
|
35
|
-
'govgr-
|
|
34
|
+
'govgr-nav__list-item-link': true,
|
|
35
|
+
'govgr-nav__list-item-link--active': active === true,
|
|
36
36
|
})}
|
|
37
37
|
{...props}
|
|
38
38
|
>
|
|
@@ -5,11 +5,11 @@ exports[`renders the NavMenu with no props 1`] = `
|
|
|
5
5
|
<ForwardRef(Base)
|
|
6
6
|
aria-hidden={true}
|
|
7
7
|
as="div"
|
|
8
|
-
className="govgr-nav-
|
|
8
|
+
className="govgr-nav-menu--horizontal govgr-nav-menu--hidden govgr-nav-menu"
|
|
9
9
|
>
|
|
10
10
|
<div
|
|
11
11
|
aria-hidden={true}
|
|
12
|
-
className="govgr-nav-
|
|
12
|
+
className="govgr-nav-menu--horizontal govgr-nav-menu--hidden govgr-nav-menu"
|
|
13
13
|
>
|
|
14
14
|
hello
|
|
15
15
|
</div>
|
package/src/NavMenu/index.tsx
CHANGED
|
@@ -30,9 +30,10 @@ export const NavMenu = React.forwardRef<HTMLDivElement, NavMenuProps>(
|
|
|
30
30
|
ref={ref}
|
|
31
31
|
aria-hidden={!active}
|
|
32
32
|
className={clsx(className, {
|
|
33
|
-
'govgr-nav-
|
|
34
|
-
'govgr-
|
|
35
|
-
'govgr-nav-
|
|
33
|
+
'govgr-nav-menu': true,
|
|
34
|
+
'govgr-nav-menu--horizontal': layout === 'horizontal',
|
|
35
|
+
'govgr-nav-menu--vertical': layout === 'vertical',
|
|
36
|
+
'govgr-nav-menu--hidden': !active,
|
|
36
37
|
})}
|
|
37
38
|
{...props}
|
|
38
39
|
>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { BaseProps } from '@digigov/react-core/Base';
|
|
3
|
-
import clsx from 'clsx';
|
|
4
3
|
import Container from '@digigov/react-core/Container';
|
|
5
4
|
|
|
6
5
|
export interface NavMenuContainerProps extends BaseProps<'div'> {
|
|
@@ -25,7 +24,7 @@ export const NavMenuContainer = React.forwardRef<
|
|
|
25
24
|
<Container
|
|
26
25
|
cols={layout === 'horizontal'}
|
|
27
26
|
ref={ref}
|
|
28
|
-
className={
|
|
27
|
+
className={className}
|
|
29
28
|
{...props}
|
|
30
29
|
>
|
|
31
30
|
{children}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { BaseProps } from '@digigov/react-core/Base';
|
|
3
|
-
import clsx from 'clsx';
|
|
4
3
|
import Grid from '@digigov/react-core/Grid';
|
|
5
4
|
|
|
6
5
|
export interface NavMenuContainerContentProps extends BaseProps<'div'> {}
|
|
@@ -14,7 +13,7 @@ export const NavMenuContainerContent = React.forwardRef<
|
|
|
14
13
|
NavMenuContainerContentProps
|
|
15
14
|
>(function NavMenuContainerContent({ className, children, ...props }, ref) {
|
|
16
15
|
return (
|
|
17
|
-
<Grid item md={2} ref={ref} className={
|
|
16
|
+
<Grid item md={2} ref={ref} className={className} {...props}>
|
|
18
17
|
{children}
|
|
19
18
|
</Grid>
|
|
20
19
|
);
|
|
@@ -4,10 +4,10 @@ exports[`renders the NavMenuContainerContentList with no props 1`] = `
|
|
|
4
4
|
<ForwardRef(NavMenuContainerContentList)>
|
|
5
5
|
<ForwardRef(Base)
|
|
6
6
|
as="ul"
|
|
7
|
-
className="govgr-nav-
|
|
7
|
+
className="govgr-nav-menu__content-list"
|
|
8
8
|
>
|
|
9
9
|
<ul
|
|
10
|
-
className="govgr-nav-
|
|
10
|
+
className="govgr-nav-menu__content-list"
|
|
11
11
|
>
|
|
12
12
|
hello
|
|
13
13
|
</ul>
|
|
@@ -2,13 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import Base, { BaseProps } from '@digigov/react-core/Base';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
|
|
5
|
-
export interface NavMenuContainerContentListProps extends BaseProps<'ul'> {
|
|
6
|
-
/**
|
|
7
|
-
* layout prop sets the display layout for the nav list
|
|
8
|
-
* layout is horizontal by default.
|
|
9
|
-
*/
|
|
10
|
-
layout?: 'vertical' | 'horizontal';
|
|
11
|
-
}
|
|
5
|
+
export interface NavMenuContainerContentListProps extends BaseProps<'ul'> {}
|
|
12
6
|
/**
|
|
13
7
|
* NavMenuContainerContentList contains the ul list nav menu.
|
|
14
8
|
* Inside this component must be NavMenuContainerContentListItem component.
|
|
@@ -16,17 +10,13 @@ export interface NavMenuContainerContentListProps extends BaseProps<'ul'> {
|
|
|
16
10
|
export const NavMenuContainerContentList = React.forwardRef<
|
|
17
11
|
HTMLUListElement,
|
|
18
12
|
NavMenuContainerContentListProps
|
|
19
|
-
>(function NavMenuContainerContentList(
|
|
20
|
-
{ className, layout = 'horizontal', children, ...props },
|
|
21
|
-
ref
|
|
22
|
-
) {
|
|
13
|
+
>(function NavMenuContainerContentList({ className, children, ...props }, ref) {
|
|
23
14
|
return (
|
|
24
15
|
<Base
|
|
25
16
|
as="ul"
|
|
26
17
|
ref={ref}
|
|
27
18
|
className={clsx(className, {
|
|
28
|
-
'govgr-nav-
|
|
29
|
-
'govgr-vertical-nav-list__content-list': layout === 'vertical',
|
|
19
|
+
'govgr-nav-menu__content-list': true,
|
|
30
20
|
})}
|
|
31
21
|
{...props}
|
|
32
22
|
>
|
|
@@ -4,10 +4,10 @@ exports[`renders the NavMenuContainerContentListItem with no props 1`] = `
|
|
|
4
4
|
<ForwardRef(NavMenuContainerContentListItem)>
|
|
5
5
|
<ForwardRef(Base)
|
|
6
6
|
as="li"
|
|
7
|
-
className="govgr-nav-
|
|
7
|
+
className="govgr-nav-menu__content-list-item"
|
|
8
8
|
>
|
|
9
9
|
<li
|
|
10
|
-
className="govgr-nav-
|
|
10
|
+
className="govgr-nav-menu__content-list-item"
|
|
11
11
|
>
|
|
12
12
|
hello
|
|
13
13
|
</li>
|
|
@@ -4,13 +4,7 @@ import clsx from 'clsx';
|
|
|
4
4
|
import Grid from '@digigov/react-core/Grid';
|
|
5
5
|
import Heading from '@digigov/react-core/Heading';
|
|
6
6
|
|
|
7
|
-
export interface NavMenuContainerTitleProps extends BaseProps<'div'> {
|
|
8
|
-
/**
|
|
9
|
-
* layout prop sets the display layout for the nav list
|
|
10
|
-
* layout is horizontal by default.
|
|
11
|
-
*/
|
|
12
|
-
layout?: 'horizontal' | 'vertical';
|
|
13
|
-
}
|
|
7
|
+
export interface NavMenuContainerTitleProps extends BaseProps<'div'> {}
|
|
14
8
|
/**
|
|
15
9
|
*
|
|
16
10
|
* NavMenuContainerTitle is the main Title for the nav list items.
|
|
@@ -19,17 +13,14 @@ export interface NavMenuContainerTitleProps extends BaseProps<'div'> {
|
|
|
19
13
|
export const NavMenuContainerTitle = React.forwardRef<
|
|
20
14
|
HTMLDivElement,
|
|
21
15
|
NavMenuContainerTitleProps
|
|
22
|
-
>(function NavMenuContainerTitle(
|
|
23
|
-
{ className, layout = 'horizontal', children, ...props },
|
|
24
|
-
ref
|
|
25
|
-
) {
|
|
16
|
+
>(function NavMenuContainerTitle({ className, children, ...props }, ref) {
|
|
26
17
|
return (
|
|
27
18
|
<Grid
|
|
28
19
|
item
|
|
29
20
|
md={1}
|
|
30
21
|
ref={ref}
|
|
31
22
|
className={clsx(className, {
|
|
32
|
-
'govgr-
|
|
23
|
+
'govgr-nav-menu__container-title': true,
|
|
33
24
|
})}
|
|
34
25
|
{...props}
|
|
35
26
|
>
|
|
@@ -37,8 +28,7 @@ export const NavMenuContainerTitle = React.forwardRef<
|
|
|
37
28
|
element="h3"
|
|
38
29
|
size="m"
|
|
39
30
|
className={clsx({
|
|
40
|
-
'govgr-
|
|
41
|
-
layout === 'vertical',
|
|
31
|
+
'govgr-nav-menu__container-title-heading': true,
|
|
42
32
|
})}
|
|
43
33
|
>
|
|
44
34
|
{children}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`renders the SingleCharacterInputContainer with no props 1`] = `
|
|
4
|
+
<ForwardRef(SingleCharacterInputContainer)>
|
|
5
|
+
<ForwardRef(Base)
|
|
6
|
+
as="div"
|
|
7
|
+
className="govgr-single-character-input--container"
|
|
8
|
+
>
|
|
9
|
+
<div
|
|
10
|
+
className="govgr-single-character-input--container"
|
|
11
|
+
>
|
|
12
|
+
hello
|
|
13
|
+
</div>
|
|
14
|
+
</ForwardRef(Base)>
|
|
15
|
+
</ForwardRef(SingleCharacterInputContainer)>
|
|
16
|
+
`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { mount } from 'enzyme';
|
|
3
|
+
|
|
4
|
+
import SingleCharacterInputContainer from '@digigov/react-core/SingleCharacterInputContainer';
|
|
5
|
+
|
|
6
|
+
it('renders the SingleCharacterInputContainer with no props', () => {
|
|
7
|
+
expect(
|
|
8
|
+
mount(<SingleCharacterInputContainer>hello</SingleCharacterInputContainer>)
|
|
9
|
+
).toMatchSnapshot();
|
|
10
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Base, { BaseProps } from '@digigov/react-core/Base';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
|
|
5
|
+
export interface SingleCharacterInputContainerProps extends BaseProps<'div'> {}
|
|
6
|
+
/**
|
|
7
|
+
* Details for the SingleCharacterInputContainer.
|
|
8
|
+
* It is used as a parent component to wrap SingleCharacterInput component.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export const SingleCharacterInputContainer = React.forwardRef<
|
|
12
|
+
HTMLDivElement,
|
|
13
|
+
SingleCharacterInputContainerProps
|
|
14
|
+
>(function SingleCharacterInputContainer(
|
|
15
|
+
{ className, children, ...props },
|
|
16
|
+
ref
|
|
17
|
+
) {
|
|
18
|
+
return (
|
|
19
|
+
<Base
|
|
20
|
+
as="div"
|
|
21
|
+
ref={ref}
|
|
22
|
+
className={clsx(className, {
|
|
23
|
+
'govgr-single-character-input--container': true,
|
|
24
|
+
})}
|
|
25
|
+
{...props}
|
|
26
|
+
>
|
|
27
|
+
{children}
|
|
28
|
+
</Base>
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export default SingleCharacterInputContainer;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`renders the SingleCharacterInputItem with maxLength prop 1`] = `
|
|
4
|
+
<ForwardRef(SingleCharacterInputItem)
|
|
5
|
+
maxLength={6}
|
|
6
|
+
>
|
|
7
|
+
<ForwardRef(Base)
|
|
8
|
+
as="input"
|
|
9
|
+
className="govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
10
|
+
inputMode="numeric"
|
|
11
|
+
maxLength={6}
|
|
12
|
+
pattern="[0-9]*"
|
|
13
|
+
type="text"
|
|
14
|
+
>
|
|
15
|
+
<input
|
|
16
|
+
className="govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
17
|
+
inputMode="numeric"
|
|
18
|
+
maxLength={6}
|
|
19
|
+
pattern="[0-9]*"
|
|
20
|
+
type="text"
|
|
21
|
+
/>
|
|
22
|
+
</ForwardRef(Base)>
|
|
23
|
+
</ForwardRef(SingleCharacterInputItem)>
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
exports[`renders the SingleCharacterInputItem with name and error props 1`] = `
|
|
27
|
+
<ForwardRef(SingleCharacterInputItem)
|
|
28
|
+
error={true}
|
|
29
|
+
name="single-character-input"
|
|
30
|
+
>
|
|
31
|
+
<ForwardRef(Base)
|
|
32
|
+
as="input"
|
|
33
|
+
className="govgr-error-input govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
34
|
+
inputMode="numeric"
|
|
35
|
+
maxLength={1}
|
|
36
|
+
name="single-character-input"
|
|
37
|
+
pattern="[0-9]*"
|
|
38
|
+
type="text"
|
|
39
|
+
>
|
|
40
|
+
<input
|
|
41
|
+
className="govgr-error-input govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
42
|
+
inputMode="numeric"
|
|
43
|
+
maxLength={1}
|
|
44
|
+
name="single-character-input"
|
|
45
|
+
pattern="[0-9]*"
|
|
46
|
+
type="text"
|
|
47
|
+
/>
|
|
48
|
+
</ForwardRef(Base)>
|
|
49
|
+
</ForwardRef(SingleCharacterInputItem)>
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
exports[`renders the SingleCharacterInputItem with name and error props 2`] = `
|
|
53
|
+
<ForwardRef(SingleCharacterInputItem)
|
|
54
|
+
error={true}
|
|
55
|
+
name="single-character-input"
|
|
56
|
+
>
|
|
57
|
+
<ForwardRef(Base)
|
|
58
|
+
as="input"
|
|
59
|
+
className="govgr-error-input govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
60
|
+
inputMode="numeric"
|
|
61
|
+
maxLength={1}
|
|
62
|
+
name="single-character-input"
|
|
63
|
+
pattern="[0-9]*"
|
|
64
|
+
type="text"
|
|
65
|
+
>
|
|
66
|
+
<input
|
|
67
|
+
className="govgr-error-input govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
68
|
+
inputMode="numeric"
|
|
69
|
+
maxLength={1}
|
|
70
|
+
name="single-character-input"
|
|
71
|
+
pattern="[0-9]*"
|
|
72
|
+
type="text"
|
|
73
|
+
/>
|
|
74
|
+
</ForwardRef(Base)>
|
|
75
|
+
</ForwardRef(SingleCharacterInputItem)>
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
exports[`renders the SingleCharacterInputItem with name prop 1`] = `
|
|
79
|
+
<ForwardRef(SingleCharacterInputItem)
|
|
80
|
+
name="single-character-input"
|
|
81
|
+
>
|
|
82
|
+
<ForwardRef(Base)
|
|
83
|
+
as="input"
|
|
84
|
+
className="govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
85
|
+
inputMode="numeric"
|
|
86
|
+
maxLength={1}
|
|
87
|
+
name="single-character-input"
|
|
88
|
+
pattern="[0-9]*"
|
|
89
|
+
type="text"
|
|
90
|
+
>
|
|
91
|
+
<input
|
|
92
|
+
className="govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
93
|
+
inputMode="numeric"
|
|
94
|
+
maxLength={1}
|
|
95
|
+
name="single-character-input"
|
|
96
|
+
pattern="[0-9]*"
|
|
97
|
+
type="text"
|
|
98
|
+
/>
|
|
99
|
+
</ForwardRef(Base)>
|
|
100
|
+
</ForwardRef(SingleCharacterInputItem)>
|
|
101
|
+
`;
|
|
102
|
+
|
|
103
|
+
exports[`renders the SingleCharacterInputItem with name, pattern, maxLength and error props 1`] = `
|
|
104
|
+
<ForwardRef(SingleCharacterInputItem)
|
|
105
|
+
error={true}
|
|
106
|
+
maxLength={6}
|
|
107
|
+
name="single-character-input"
|
|
108
|
+
pattern="\\\\d{1}"
|
|
109
|
+
>
|
|
110
|
+
<ForwardRef(Base)
|
|
111
|
+
as="input"
|
|
112
|
+
className="govgr-error-input govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
113
|
+
inputMode="numeric"
|
|
114
|
+
maxLength={6}
|
|
115
|
+
name="single-character-input"
|
|
116
|
+
pattern="\\\\d{1}"
|
|
117
|
+
type="text"
|
|
118
|
+
>
|
|
119
|
+
<input
|
|
120
|
+
className="govgr-error-input govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
121
|
+
inputMode="numeric"
|
|
122
|
+
maxLength={6}
|
|
123
|
+
name="single-character-input"
|
|
124
|
+
pattern="\\\\d{1}"
|
|
125
|
+
type="text"
|
|
126
|
+
/>
|
|
127
|
+
</ForwardRef(Base)>
|
|
128
|
+
</ForwardRef(SingleCharacterInputItem)>
|
|
129
|
+
`;
|
|
130
|
+
|
|
131
|
+
exports[`renders the SingleCharacterInputItem with no props 1`] = `
|
|
132
|
+
<ForwardRef(SingleCharacterInputItem)>
|
|
133
|
+
<ForwardRef(Base)
|
|
134
|
+
as="input"
|
|
135
|
+
className="govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
136
|
+
inputMode="numeric"
|
|
137
|
+
maxLength={1}
|
|
138
|
+
pattern="[0-9]*"
|
|
139
|
+
type="text"
|
|
140
|
+
>
|
|
141
|
+
<input
|
|
142
|
+
className="govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
143
|
+
inputMode="numeric"
|
|
144
|
+
maxLength={1}
|
|
145
|
+
pattern="[0-9]*"
|
|
146
|
+
type="text"
|
|
147
|
+
/>
|
|
148
|
+
</ForwardRef(Base)>
|
|
149
|
+
</ForwardRef(SingleCharacterInputItem)>
|
|
150
|
+
`;
|
|
151
|
+
|
|
152
|
+
exports[`renders the SingleCharacterInputItem with pattern prop 1`] = `
|
|
153
|
+
<ForwardRef(SingleCharacterInputItem)
|
|
154
|
+
pattern="\\\\d{1}"
|
|
155
|
+
>
|
|
156
|
+
<ForwardRef(Base)
|
|
157
|
+
as="input"
|
|
158
|
+
className="govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
159
|
+
inputMode="numeric"
|
|
160
|
+
maxLength={1}
|
|
161
|
+
pattern="\\\\d{1}"
|
|
162
|
+
type="text"
|
|
163
|
+
>
|
|
164
|
+
<input
|
|
165
|
+
className="govgr-otp-input__item govgr-input govgr-otp-input--width"
|
|
166
|
+
inputMode="numeric"
|
|
167
|
+
maxLength={1}
|
|
168
|
+
pattern="\\\\d{1}"
|
|
169
|
+
type="text"
|
|
170
|
+
/>
|
|
171
|
+
</ForwardRef(Base)>
|
|
172
|
+
</ForwardRef(SingleCharacterInputItem)>
|
|
173
|
+
`;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { mount } from 'enzyme';
|
|
3
|
+
|
|
4
|
+
import SingleCharacterInputItem from '@digigov/react-core/SingleCharacterInputItem';
|
|
5
|
+
|
|
6
|
+
it('renders the SingleCharacterInputItem with no props', () => {
|
|
7
|
+
expect(mount(<SingleCharacterInputItem />)).toMatchSnapshot();
|
|
8
|
+
});
|
|
9
|
+
it('renders the SingleCharacterInputItem with maxLength prop', () => {
|
|
10
|
+
expect(mount(<SingleCharacterInputItem maxLength={6} />)).toMatchSnapshot();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('renders the SingleCharacterInputItem with name prop', () => {
|
|
14
|
+
expect(
|
|
15
|
+
mount(<SingleCharacterInputItem name={'single-character-input'} />)
|
|
16
|
+
).toMatchSnapshot();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('renders the SingleCharacterInputItem with name and error props', () => {
|
|
20
|
+
expect(
|
|
21
|
+
mount(<SingleCharacterInputItem name={'single-character-input'} error />)
|
|
22
|
+
).toMatchSnapshot();
|
|
23
|
+
});
|
|
24
|
+
it('renders the SingleCharacterInputItem with pattern prop', () => {
|
|
25
|
+
expect(mount(<SingleCharacterInputItem pattern="\d{1}" />)).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('renders the SingleCharacterInputItem with name and error props', () => {
|
|
29
|
+
expect(
|
|
30
|
+
mount(<SingleCharacterInputItem name={'single-character-input'} error />)
|
|
31
|
+
).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('renders the SingleCharacterInputItem with name, pattern, maxLength and error props', () => {
|
|
35
|
+
expect(
|
|
36
|
+
mount(
|
|
37
|
+
<SingleCharacterInputItem
|
|
38
|
+
name={'single-character-input'}
|
|
39
|
+
pattern="\d{1}"
|
|
40
|
+
maxLength={6}
|
|
41
|
+
error
|
|
42
|
+
/>
|
|
43
|
+
)
|
|
44
|
+
).toMatchSnapshot();
|
|
45
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Base, { BaseProps } from '@digigov/react-core/Base';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
|
|
5
|
+
export interface SingleCharacterInputItemProps extends BaseProps<'input'> {
|
|
6
|
+
/**
|
|
7
|
+
* Name property is optional
|
|
8
|
+
* Name prop contains a single value which describes the name of the <input> element.
|
|
9
|
+
*/
|
|
10
|
+
name?: string;
|
|
11
|
+
/**
|
|
12
|
+
* error is optional. The default value is false.
|
|
13
|
+
* Use this prop when there is an error at the input.
|
|
14
|
+
*/
|
|
15
|
+
error?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* pattern is optional. The default value is [0-9].
|
|
18
|
+
* Use this prop when you want to give a specific format input.
|
|
19
|
+
*/
|
|
20
|
+
pattern?: string;
|
|
21
|
+
/**
|
|
22
|
+
* maxLength property is optional
|
|
23
|
+
* maxLength prop specifies the max length of the input field.
|
|
24
|
+
* maxLength default value is 1.
|
|
25
|
+
*/
|
|
26
|
+
maxLength?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Details for the SingleCharacterInputItem.
|
|
30
|
+
* SingleCharacterInputItem component is used for displaying simple digital character inputs.
|
|
31
|
+
* SingleCharacterInputItem component must be included inside SingleCharacterInputContainer component as children component
|
|
32
|
+
*/
|
|
33
|
+
export const SingleCharacterInputItem = React.forwardRef<
|
|
34
|
+
HTMLInputElement,
|
|
35
|
+
SingleCharacterInputItemProps
|
|
36
|
+
>(function SingleCharacterInputItem(
|
|
37
|
+
{ name, error, className, pattern = '[0-9]*', maxLength = 1, ...props },
|
|
38
|
+
ref
|
|
39
|
+
) {
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<Base
|
|
43
|
+
as="input"
|
|
44
|
+
ref={ref}
|
|
45
|
+
type="text"
|
|
46
|
+
pattern={pattern}
|
|
47
|
+
maxLength={maxLength}
|
|
48
|
+
inputMode="numeric"
|
|
49
|
+
name={name}
|
|
50
|
+
className={clsx({
|
|
51
|
+
className,
|
|
52
|
+
'govgr-otp-input__item': true,
|
|
53
|
+
'govgr-input': true,
|
|
54
|
+
'govgr-otp-input--width': true,
|
|
55
|
+
'govgr-error-input': error === true,
|
|
56
|
+
})}
|
|
57
|
+
{...props}
|
|
58
|
+
/>
|
|
59
|
+
</>
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export default SingleCharacterInputItem;
|
package/src/index.ts
CHANGED
|
@@ -121,6 +121,8 @@ export * from '@digigov/react-core/RadioConditional';
|
|
|
121
121
|
export * from '@digigov/react-core/SectionBreak';
|
|
122
122
|
export * from '@digigov/react-core/SelectContainer';
|
|
123
123
|
export * from '@digigov/react-core/SelectOption';
|
|
124
|
+
export * from '@digigov/react-core/SingleCharacterInputContainer';
|
|
125
|
+
export * from '@digigov/react-core/SingleCharacterInputItem';
|
|
124
126
|
export * from '@digigov/react-core/SkipLink';
|
|
125
127
|
export * from '@digigov/react-core/SummaryList';
|
|
126
128
|
export * from '@digigov/react-core/SummaryListItem';
|