@ndla/ui 27.1.1 → 27.1.2
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/es/MyNdla/Resource/FolderInput.js +65 -77
- package/es/Resource/resourceComponents.js +13 -13
- package/es/TreeStructure/AddFolderButton.js +87 -0
- package/es/TreeStructure/ComboboxButton.js +13 -64
- package/es/TreeStructure/FolderItem.js +12 -12
- package/es/TreeStructure/FolderItems.js +12 -14
- package/es/TreeStructure/TreeStructure.js +55 -41
- package/es/locale/messages-en.js +1 -1
- package/es/locale/messages-nb.js +1 -1
- package/es/locale/messages-nn.js +1 -1
- package/es/locale/messages-se.js +1 -1
- package/es/locale/messages-sma.js +1 -1
- package/lib/MyNdla/Resource/FolderInput.d.ts +7 -6
- package/lib/MyNdla/Resource/FolderInput.js +65 -73
- package/lib/Resource/resourceComponents.js +13 -13
- package/lib/TreeStructure/AddFolderButton.d.ts +16 -0
- package/lib/TreeStructure/AddFolderButton.js +100 -0
- package/lib/TreeStructure/ComboboxButton.d.ts +0 -4
- package/lib/TreeStructure/ComboboxButton.js +19 -64
- package/lib/TreeStructure/FolderItem.js +12 -12
- package/lib/TreeStructure/FolderItems.d.ts +4 -3
- package/lib/TreeStructure/FolderItems.js +12 -15
- package/lib/TreeStructure/TreeStructure.d.ts +3 -4
- package/lib/TreeStructure/TreeStructure.js +55 -41
- package/lib/TreeStructure/types.d.ts +7 -1
- package/lib/locale/messages-en.js +1 -1
- package/lib/locale/messages-nb.js +1 -1
- package/lib/locale/messages-nn.js +1 -1
- package/lib/locale/messages-se.js +1 -1
- package/lib/locale/messages-sma.js +1 -1
- package/package.json +6 -6
- package/src/.DS_Store +0 -0
- package/src/MyNdla/Resource/FolderInput.tsx +69 -73
- package/src/Resource/resourceComponents.tsx +4 -6
- package/src/TreeStructure/AddFolderButton.tsx +79 -0
- package/src/TreeStructure/ComboboxButton.tsx +8 -53
- package/src/TreeStructure/FolderItem.tsx +5 -4
- package/src/TreeStructure/FolderItems.tsx +8 -15
- package/src/TreeStructure/TreeStructure.tsx +42 -33
- package/src/TreeStructure/types.ts +13 -1
- package/src/locale/messages-en.ts +1 -1
- package/src/locale/messages-nb.ts +1 -1
- package/src/locale/messages-nn.ts +1 -1
- package/src/locale/messages-se.ts +1 -1
- package/src/locale/messages-sma.ts +1 -1
- package/es/TreeStructure/FolderNameInput.js +0 -143
- package/lib/TreeStructure/FolderNameInput.d.ts +0 -19
- package/lib/TreeStructure/FolderNameInput.js +0 -159
- package/src/TreeStructure/FolderNameInput.tsx +0 -167
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2022-present, NDLA.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import React, { useEffect, useState, useRef, ChangeEvent, KeyboardEvent } from 'react';
|
|
10
|
-
import styled from '@emotion/styled';
|
|
11
|
-
import { spacing, colors, animations, spacingUnit } from '@ndla/core';
|
|
12
|
-
import { useTranslation } from 'react-i18next';
|
|
13
|
-
import { isMobile } from 'react-device-detect';
|
|
14
|
-
import { Spinner } from '@ndla/icons';
|
|
15
|
-
import { IconButton } from '@ndla/button';
|
|
16
|
-
import { Cross } from '@ndla/icons/action';
|
|
17
|
-
import { Done } from '@ndla/icons/editor';
|
|
18
|
-
import { InputV2 as Input } from '@ndla/forms';
|
|
19
|
-
import { TreeStructureType } from './types';
|
|
20
|
-
import { treestructureId } from './helperFunctions';
|
|
21
|
-
|
|
22
|
-
// Source: https://kovart.github.io/dashed-border-generator/
|
|
23
|
-
const borderStyle = `url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' stroke='${encodeURIComponent(
|
|
24
|
-
colors.brand.tertiary,
|
|
25
|
-
)}' stroke-width='2' stroke-dasharray='8%2c8' stroke-dashoffset='4' stroke-linecap='square'/%3e%3c/svg%3e")`;
|
|
26
|
-
|
|
27
|
-
const NewFolderWrapper = styled.div`
|
|
28
|
-
background: linear-gradient(
|
|
29
|
-
to bottom,
|
|
30
|
-
${colors.white} 0%,
|
|
31
|
-
${colors.white} 15%,
|
|
32
|
-
${colors.brand.lighter} 15%,
|
|
33
|
-
${colors.brand.lighter} 85%,
|
|
34
|
-
${colors.white} 85%,
|
|
35
|
-
${colors.white} 100%
|
|
36
|
-
);
|
|
37
|
-
background-size: auto 100%;
|
|
38
|
-
`;
|
|
39
|
-
|
|
40
|
-
const Row = styled.div`
|
|
41
|
-
display: flex;
|
|
42
|
-
gap: ${spacing.xxsmall};
|
|
43
|
-
padding-right: ${spacing.xsmall};
|
|
44
|
-
`;
|
|
45
|
-
|
|
46
|
-
const InputWrapper = styled.div<{ level: number }>`
|
|
47
|
-
display: flex;
|
|
48
|
-
margin: ${spacing.xxsmall} 0;
|
|
49
|
-
margin-left: ${({ level }) => 0.75 * spacingUnit * level + 2 * spacingUnit}px;
|
|
50
|
-
margin-right: ${spacing.normal};
|
|
51
|
-
align-items: center;
|
|
52
|
-
background-color: ${colors.white};
|
|
53
|
-
background-image: ${borderStyle};
|
|
54
|
-
color: ${colors.brand.primary};
|
|
55
|
-
|
|
56
|
-
${animations.fadeInLeft(animations.durations.fast)};
|
|
57
|
-
animation-fill-mode: forwards;
|
|
58
|
-
@media (prefers-reduced-motion: reduce) {
|
|
59
|
-
animation: none;
|
|
60
|
-
}
|
|
61
|
-
`;
|
|
62
|
-
|
|
63
|
-
const StyledInput = styled(Input)`
|
|
64
|
-
padding: ${spacing.small};
|
|
65
|
-
flex-grow: 1;
|
|
66
|
-
border: 0;
|
|
67
|
-
outline: none;
|
|
68
|
-
min-width: 0;
|
|
69
|
-
background: transparent;
|
|
70
|
-
color: ${colors.brand.primary};
|
|
71
|
-
scroll-margin-top: 100px;
|
|
72
|
-
`;
|
|
73
|
-
|
|
74
|
-
interface FolderNameInputProps {
|
|
75
|
-
onSaveNewFolder: (name: string, parentId: string) => void;
|
|
76
|
-
parentId: string;
|
|
77
|
-
onCancelNewFolder: () => void;
|
|
78
|
-
loading?: boolean;
|
|
79
|
-
level: number;
|
|
80
|
-
type: TreeStructureType;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const FolderNameInput = ({
|
|
84
|
-
onSaveNewFolder,
|
|
85
|
-
parentId,
|
|
86
|
-
onCancelNewFolder,
|
|
87
|
-
loading,
|
|
88
|
-
level,
|
|
89
|
-
type,
|
|
90
|
-
}: FolderNameInputProps) => {
|
|
91
|
-
const { t } = useTranslation();
|
|
92
|
-
const [name, setName] = useState<string>('');
|
|
93
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
94
|
-
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
if (isMobile) {
|
|
97
|
-
inputRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
98
|
-
}
|
|
99
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
|
-
}, []);
|
|
101
|
-
|
|
102
|
-
return (
|
|
103
|
-
<NewFolderWrapper>
|
|
104
|
-
<InputWrapper level={level}>
|
|
105
|
-
<StyledInput
|
|
106
|
-
name="name"
|
|
107
|
-
labelHidden
|
|
108
|
-
label={t('treeStructure.newFolder.folderName')}
|
|
109
|
-
aria-invalid={name.length === 0}
|
|
110
|
-
aria-disabled={loading ? true : undefined}
|
|
111
|
-
aria-describedby={loading ? treestructureId(type, 'spinner') : undefined}
|
|
112
|
-
ref={inputRef}
|
|
113
|
-
autoFocus
|
|
114
|
-
placeholder={t('treeStructure.newFolder.placeholder')}
|
|
115
|
-
value={name}
|
|
116
|
-
onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {
|
|
117
|
-
if (e.key === 'Escape') {
|
|
118
|
-
e.preventDefault();
|
|
119
|
-
onCancelNewFolder();
|
|
120
|
-
} else if (e.key === 'Enter') {
|
|
121
|
-
e.preventDefault();
|
|
122
|
-
if (name === '' || loading) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
onSaveNewFolder(name, parentId);
|
|
126
|
-
}
|
|
127
|
-
}}
|
|
128
|
-
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
129
|
-
if (!loading) {
|
|
130
|
-
setName(e.target.value);
|
|
131
|
-
}
|
|
132
|
-
}}
|
|
133
|
-
/>
|
|
134
|
-
<Row>
|
|
135
|
-
{!loading && (
|
|
136
|
-
<>
|
|
137
|
-
<IconButton
|
|
138
|
-
tabIndex={0}
|
|
139
|
-
aria-label={t('save')}
|
|
140
|
-
title={t('save')}
|
|
141
|
-
size="small"
|
|
142
|
-
ghostPill
|
|
143
|
-
onClick={() => onSaveNewFolder(name, parentId)}>
|
|
144
|
-
<Done />
|
|
145
|
-
</IconButton>
|
|
146
|
-
<IconButton aria-label={t('close')} title={t('close')} size="small" ghostPill onClick={onCancelNewFolder}>
|
|
147
|
-
<Cross />
|
|
148
|
-
</IconButton>
|
|
149
|
-
</>
|
|
150
|
-
)}
|
|
151
|
-
<div aria-live="assertive">
|
|
152
|
-
{loading && (
|
|
153
|
-
<Spinner
|
|
154
|
-
size="normal"
|
|
155
|
-
margin={spacing.small}
|
|
156
|
-
id={treestructureId(type, 'spinner')}
|
|
157
|
-
aria-label={t('loading')}
|
|
158
|
-
/>
|
|
159
|
-
)}
|
|
160
|
-
</div>
|
|
161
|
-
</Row>
|
|
162
|
-
</InputWrapper>
|
|
163
|
-
</NewFolderWrapper>
|
|
164
|
-
);
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
export default FolderNameInput;
|