@ndla/ui 46.0.1 → 46.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.
Files changed (37) hide show
  1. package/es/Article/Article.js +12 -4
  2. package/es/Embed/AudioEmbed.js +3 -1
  3. package/es/RadioButtonGroup/RadioButtonGroup.js +99 -80
  4. package/es/index.js +0 -1
  5. package/lib/Article/Article.d.ts +6 -3
  6. package/lib/Article/Article.js +12 -4
  7. package/lib/Embed/AudioEmbed.d.ts +2 -1
  8. package/lib/Embed/AudioEmbed.js +3 -1
  9. package/lib/Figure/Figure.d.ts +1 -0
  10. package/lib/RadioButtonGroup/RadioButtonGroup.d.ts +16 -8
  11. package/lib/RadioButtonGroup/RadioButtonGroup.js +108 -84
  12. package/lib/index.d.ts +0 -2
  13. package/lib/index.js +0 -7
  14. package/package.json +3 -2
  15. package/src/Article/Article.tsx +21 -7
  16. package/src/Embed/AudioEmbed.tsx +3 -2
  17. package/src/Figure/Figure.tsx +1 -0
  18. package/src/RadioButtonGroup/RadioButtonGroup.stories.tsx +126 -0
  19. package/src/RadioButtonGroup/RadioButtonGroup.tsx +137 -104
  20. package/src/index.ts +0 -10
  21. package/es/User/UserInfo.js +0 -114
  22. package/es/User/apiTypes.js +0 -1
  23. package/es/User/index.js +0 -10
  24. package/es/User/parseUserObject.js +0 -101
  25. package/lib/User/UserInfo.d.ts +0 -12
  26. package/lib/User/UserInfo.js +0 -119
  27. package/lib/User/apiTypes.d.ts +0 -70
  28. package/lib/User/apiTypes.js +0 -5
  29. package/lib/User/index.d.ts +0 -11
  30. package/lib/User/index.js +0 -12
  31. package/lib/User/parseUserObject.d.ts +0 -33
  32. package/lib/User/parseUserObject.js +0 -107
  33. package/src/User/UserInfo.tsx +0 -101
  34. package/src/User/__tests__/parseUserObject-test.ts +0 -316
  35. package/src/User/apiTypes.ts +0 -84
  36. package/src/User/index.ts +0 -21
  37. package/src/User/parseUserObject.ts +0 -89
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Copyright (c) 2023-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 { Meta, StoryFn, StoryObj } from '@storybook/react';
10
+ import { css } from '@emotion/react';
11
+ import { colors, misc, spacing, utils } from '@ndla/core';
12
+ import RadioButtonGroup, { RadioButtonGroupRoot, RadioGroupItem } from './RadioButtonGroup';
13
+ import { defaultParameters } from '../../../../stories/defaults';
14
+
15
+ export default {
16
+ title: 'Components/RadioButtonGroup',
17
+ component: RadioButtonGroup,
18
+ tags: ['autodocs'],
19
+ parameters: {
20
+ ...defaultParameters,
21
+ },
22
+ args: {
23
+ uniqeIds: true,
24
+ label: 'Velg fag',
25
+ options: [
26
+ {
27
+ title: 'T1',
28
+ value: 't1',
29
+ },
30
+ {
31
+ title: 'R1',
32
+ value: 'r1',
33
+ },
34
+ {
35
+ title: 'R2',
36
+ value: 'r2',
37
+ },
38
+ {
39
+ title: 'S1',
40
+ value: 's1',
41
+ disabled: true,
42
+ },
43
+ ],
44
+ },
45
+ } as Meta<typeof RadioButtonGroup>;
46
+
47
+ export const RadioButtonGroupStory: StoryFn<typeof RadioButtonGroup> = ({ ...args }) => {
48
+ return <RadioButtonGroup {...args} />;
49
+ };
50
+
51
+ RadioButtonGroupStory.storyName = 'RadioButtonGroup';
52
+
53
+ export const WithStandaloneComponents: StoryObj<typeof RadioButtonGroup> = {
54
+ args: {
55
+ onChange: () => {},
56
+ direction: 'vertical',
57
+ options: [
58
+ {
59
+ title: 'Vis navnet mitt når jeg deler en mappe',
60
+ value: 'showName',
61
+ },
62
+ {
63
+ title: 'Ikke vis navnet mitt når jeg deler en mappe',
64
+ value: 'dontShowName',
65
+ },
66
+ {
67
+ title: 'Kanskje vis navnet mitt når jeg deler en mappe',
68
+ value: 'maybeShowName',
69
+ },
70
+ ],
71
+ },
72
+ render: ({ options, ...args }) => {
73
+ return (
74
+ <RadioButtonGroupRoot
75
+ value={args.selected}
76
+ direction={args.direction}
77
+ defaultValue={args.selected ?? options[0].value}
78
+ onValueChange={args.onChange}
79
+ css={css`
80
+ gap: 0px;
81
+ `}
82
+ aria-labelledby="desc"
83
+ >
84
+ <span id="desc" css={css(utils.visuallyHidden)}>
85
+ {args.label}
86
+ </span>
87
+ {options.map((option) => (
88
+ <RadioGroupItem
89
+ key={option.value}
90
+ id={option.value}
91
+ css={css`
92
+ box-sizing: content-box;
93
+ border-radius: ${misc.borderRadius};
94
+ border: 1px solid ${colors.brand.greyLight};
95
+ border-radius: 0px;
96
+ padding: ${spacing.small};
97
+ border-color: ${colors.brand.light};
98
+
99
+ &:focus-within,
100
+ &[data-state='checked'] {
101
+ outline: 0px;
102
+ border-color: ${colors.brand.primary};
103
+ border-radius: 0px;
104
+ z-index: 1;
105
+ }
106
+ &:first-of-type {
107
+ border-top-left-radius: ${misc.borderRadius};
108
+ border-top-right-radius: ${misc.borderRadius};
109
+ }
110
+ &:not(:first-of-type) {
111
+ margin-top: -1px;
112
+ }
113
+ &:last-of-type {
114
+ border-bottom-left-radius: ${misc.borderRadius};
115
+ border-bottom-right-radius: ${misc.borderRadius};
116
+ }
117
+ `}
118
+ value={option.value}
119
+ title={option.title}
120
+ disabled={option.disabled}
121
+ />
122
+ ))}
123
+ </RadioButtonGroupRoot>
124
+ );
125
+ },
126
+ };
@@ -6,147 +6,180 @@
6
6
  *
7
7
  */
8
8
 
9
- import { Fragment, Component, ChangeEvent } from 'react';
9
+ import { useMemo } from 'react';
10
10
  import styled from '@emotion/styled';
11
- import { uuid } from '@ndla/util';
12
- import { spacing, fonts, colors } from '@ndla/core';
11
+ import { uuid as uuidFunc } from '@ndla/util';
12
+ import { Text } from '@ndla/typography';
13
+ import { spacing, fonts, colors, misc } from '@ndla/core';
14
+ import { Indicator, Item, RadioGroupItemProps, RadioGroupProps, Root } from '@radix-ui/react-radio-group';
13
15
 
14
16
  interface Props {
15
17
  selected?: string;
18
+ className?: string;
16
19
  options: {
17
20
  title: string;
18
21
  value: string;
19
22
  disabled?: boolean;
20
23
  }[];
24
+ direction?: 'horizontal' | 'vertical';
21
25
  label?: string;
22
26
  uniqeIds?: boolean;
23
27
  onChange: (value: string) => void;
24
28
  }
25
29
 
26
- interface State {
27
- selected: string;
28
- }
30
+ const GroupLabel = styled(Text)`
31
+ font-family: ${fonts.sans};
32
+ font-weight: ${fonts.weight.semibold};
33
+ `;
29
34
 
30
- const RadioButtonGroupWrapper = styled.div`
31
- padding: ${spacing.small} 0;
35
+ const RadioButtonGroupLabel = styled(Text)`
36
+ color: ${colors.brand.primary};
32
37
  font-family: ${fonts.sans};
38
+ &[data-disabled='true'] {
39
+ color: ${colors.brand.light};
40
+ }
41
+ `;
42
+
43
+ const RadioButtonWrapper = styled.div`
33
44
  display: flex;
34
45
  align-items: center;
46
+ padding: 0px ${spacing.small};
47
+ gap: ${spacing.small};
48
+ &:focus-within {
49
+ outline: 2px solid ${colors.brand.primary};
50
+ border-radius: ${misc.borderRadius};
51
+ }
35
52
  `;
36
53
 
37
- const RadioButtonGroupLabelHeading = styled.h1`
38
- ${fonts.sizes('16px', '20px')};
39
- margin: 0 ${spacing.normal} 0 0;
40
- font-weight: 600;
54
+ export const StyledRadioGroupItem = styled(Item)`
55
+ all: unset;
56
+ transition: 200ms all ease;
57
+ box-shadow: 0 0 0 2px ${colors.brand.light};
58
+ min-width: ${spacing.nsmall};
59
+ min-height: ${spacing.nsmall};
60
+ width: ${spacing.nsmall};
61
+ height: ${spacing.nsmall};
62
+ border-radius: 100%;
63
+ &[data-state='checked'] {
64
+ box-shadow: 0 0 0 2px ${colors.brand.primary};
65
+ }
41
66
  `;
42
67
 
43
- const RadioButtonGroupLabel = styled.label`
44
- ${fonts.sizes('16px', '28px')};
45
- color: ${colors.brand.primary};
68
+ const RadioButtonIndicator = styled(Indicator)`
69
+ display: flex;
46
70
  align-items: center;
47
- display: inline-flex;
48
- &:before {
49
- content: '';
50
- margin-right: ${spacing.small};
51
- width: 20px;
52
- height: 20px;
53
- border-radius: 100%;
54
- border: 2px solid ${colors.brand.tertiary};
55
- transition: 200ms border-color ease;
56
- }
57
- &:after {
71
+ justify-content: center;
72
+ width: 100%;
73
+ height: 100%;
74
+
75
+ &::after {
58
76
  content: '';
59
- background: transparent;
60
- width: 10px;
61
- height: 10px;
62
- border-radius: 100%;
63
- position: absolute;
64
- transform: translateX(5px) scale(0, 0);
77
+ display: block;
78
+ width: 0px;
79
+ height: 0px;
80
+ border-radius: 50%;
81
+ background-color: ${colors.brand.light};
65
82
  transition: 200ms all ease;
66
83
  }
67
- &:not(:last-child) {
68
- margin-right: ${spacing.medium};
69
- }
70
- `;
71
-
72
- const RadioButtonGroupInput = styled.input`
73
- opacity: 0;
74
- position: absolute;
75
- width: auto;
76
- &:hover + ${RadioButtonGroupLabel} {
77
- outline: 1px dotted #212121;
78
- outline: -webkit-focus-ring-color auto 5px;
79
- &:after {
80
- transform: translateX(5px) scale(1, 1);
81
- background: ${colors.brand.tertiary};
84
+ &:hover,
85
+ &:focus-visible,
86
+ &[data-state='checked'] {
87
+ &::after {
88
+ width: ${spacing.small};
89
+ height: ${spacing.small};
82
90
  }
83
91
  }
84
- // emotion does not seem to support several selectors combined with targeting another emotion component
85
- // so we duplicate the css for :hover and :focus.
86
- &:focus + ${RadioButtonGroupLabel} {
87
- outline: 1px dotted #212121;
88
- outline: -webkit-focus-ring-color auto 5px;
89
- &:after {
90
- transform: translateX(5px) scale(1, 1);
91
- background: ${colors.brand.tertiary};
92
+ &[data-disabled] {
93
+ &::after {
94
+ width: 0px;
95
+ height: 0px;
92
96
  }
93
97
  }
94
- &:checked + ${RadioButtonGroupLabel} {
95
- &:before {
96
- border-color: ${colors.brand.primary};
97
- }
98
- &:after {
99
- transform: translateX(5px) scale(1, 1);
100
- background: ${colors.brand.primary};
98
+
99
+ &[data-state='checked'] {
100
+ &::after {
101
+ background-color: ${colors.brand.primary};
101
102
  }
102
103
  }
103
104
  `;
104
105
 
105
- class RadioButtonGroup extends Component<Props, State> {
106
- private readonly uuid?: string;
107
- constructor(props: Props) {
108
- super(props);
109
- this.state = {
110
- selected: props.selected || props.options[0].value,
111
- };
112
- this.handleOnChange = this.handleOnChange.bind(this);
113
- this.uuid = this.props.uniqeIds ? uuid() : undefined;
106
+ export const StyledRadioButtonGroupRoot = styled(Root)`
107
+ padding: ${spacing.small} 0;
108
+ gap: ${spacing.small};
109
+ display: flex;
110
+ font-family: ${fonts.sans};
111
+ align-items: center;
112
+ &[data-direction='vertical'] {
113
+ flex-direction: column;
114
+ align-items: unset;
114
115
  }
116
+ `;
115
117
 
116
- handleOnChange(e: ChangeEvent<HTMLInputElement>) {
117
- this.setState({
118
- selected: e.target.value,
119
- });
120
- this.props.onChange(e.target.value);
121
- }
118
+ interface ItemProps extends RadioGroupItemProps {}
122
119
 
123
- render() {
124
- return (
125
- <section>
126
- <RadioButtonGroupWrapper role="radiogroup">
127
- {this.props.label && <RadioButtonGroupLabelHeading>{this.props.label}</RadioButtonGroupLabelHeading>}
128
- {this.props.options.map((option) => {
129
- const id = this.uuid ? `${this.uuid}_${option.value}` : option.value;
130
- return (
131
- <Fragment key={option.value}>
132
- <RadioButtonGroupInput
133
- disabled={option.disabled}
134
- aria-checked={this.state.selected === option.value}
135
- checked={this.state.selected === option.value}
136
- type="radio"
137
- value={option.value}
138
- id={id}
139
- name={id}
140
- onChange={this.handleOnChange}
141
- />
142
- <RadioButtonGroupLabel htmlFor={id}>{option.title}</RadioButtonGroupLabel>
143
- </Fragment>
144
- );
145
- })}
146
- </RadioButtonGroupWrapper>
147
- </section>
148
- );
149
- }
120
+ export const RadioGroupItem = ({ value, disabled, id, title, className }: ItemProps) => {
121
+ return (
122
+ <RadioButtonWrapper key={value} className={className}>
123
+ <StyledRadioGroupItem disabled={disabled} value={value} id={id}>
124
+ <RadioButtonIndicator forceMount />
125
+ </StyledRadioGroupItem>
126
+ <RadioButtonGroupLabel element="label" textStyle="content" margin="none" htmlFor={id} data-disabled={disabled}>
127
+ {title}
128
+ </RadioButtonGroupLabel>
129
+ </RadioButtonWrapper>
130
+ );
131
+ };
132
+
133
+ interface RootProps extends RadioGroupProps {
134
+ direction?: 'horizontal' | 'vertical';
150
135
  }
151
136
 
137
+ export const RadioButtonGroupRoot = ({ children, direction, ...rest }: RootProps) => {
138
+ return (
139
+ <StyledRadioButtonGroupRoot data-direction={direction} {...rest}>
140
+ {children}
141
+ </StyledRadioButtonGroupRoot>
142
+ );
143
+ };
144
+
145
+ const RadioButtonGroup = ({
146
+ selected,
147
+ options,
148
+ label,
149
+ uniqeIds,
150
+ onChange,
151
+ direction = 'horizontal',
152
+ className,
153
+ }: Props) => {
154
+ const uuid = useMemo(() => (uniqeIds ? uuidFunc() : undefined), [uniqeIds]);
155
+
156
+ return (
157
+ <RadioButtonGroupRoot
158
+ data-direction={direction}
159
+ value={selected}
160
+ defaultValue={selected ?? options[0].value}
161
+ className={className}
162
+ onValueChange={onChange}
163
+ >
164
+ {label && (
165
+ <GroupLabel element="span" textStyle="content">
166
+ {label}
167
+ </GroupLabel>
168
+ )}
169
+ {options.map((option) => {
170
+ const id = uuid ? `${uuid}_${option.value}` : option.value;
171
+ return (
172
+ <RadioGroupItem
173
+ key={option.value}
174
+ disabled={option.disabled}
175
+ value={option.value}
176
+ id={id}
177
+ title={option.title}
178
+ />
179
+ );
180
+ })}
181
+ </RadioButtonGroupRoot>
182
+ );
183
+ };
184
+
152
185
  export default RadioButtonGroup;
package/src/index.ts CHANGED
@@ -121,16 +121,6 @@ export { default as ContentTypeResult } from './Search/ContentTypeResult';
121
121
  export { SearchFieldForm } from './Search/SearchFieldForm';
122
122
 
123
123
  export { default as MastheadSearchModal } from './Masthead/MastheadSearchModal';
124
- export { UserInfo } from './User';
125
- export type {
126
- AffiliationType,
127
- FeideGoGroup,
128
- FeideGroup,
129
- FeideOrg,
130
- FeideUserApiType,
131
- FeideMembershipType,
132
- FeideUser,
133
- } from './User';
134
124
 
135
125
  export { default as resourceTypeColor } from './utils/resourceTypeColor';
136
126
 
@@ -1,114 +0,0 @@
1
- import _styled from "@emotion/styled/base";
2
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
7
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
- function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
9
- /**
10
- * Copyright (c) 2022-present, NDLA.
11
- *
12
- * This source code is licensed under the GPLv3 license found in the
13
- * LICENSE file in the root directory of this source tree.
14
- */
15
-
16
- import { spacing } from '@ndla/core';
17
- import { useTranslation } from 'react-i18next';
18
- import { parseUserObject } from './parseUserObject';
19
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
20
- import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
21
- var InfoList = /*#__PURE__*/_styled("ul", {
22
- target: "egwtjgg1",
23
- label: "InfoList"
24
- })("padding:0 0 0 ", spacing.normal, ";" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIlVzZXJJbmZvLnRzeCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFhMEIiLCJmaWxlIjoiVXNlckluZm8udHN4Iiwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBDb3B5cmlnaHQgKGMpIDIwMjItcHJlc2VudCwgTkRMQS5cbiAqXG4gKiBUaGlzIHNvdXJjZSBjb2RlIGlzIGxpY2Vuc2VkIHVuZGVyIHRoZSBHUEx2MyBsaWNlbnNlIGZvdW5kIGluIHRoZVxuICogTElDRU5TRSBmaWxlIGluIHRoZSByb290IGRpcmVjdG9yeSBvZiB0aGlzIHNvdXJjZSB0cmVlLlxuICovXG5cbmltcG9ydCBzdHlsZWQgZnJvbSAnQGVtb3Rpb24vc3R5bGVkJztcbmltcG9ydCB7IHNwYWNpbmcgfSBmcm9tICdAbmRsYS9jb3JlJztcbmltcG9ydCB7IHVzZVRyYW5zbGF0aW9uIH0gZnJvbSAncmVhY3QtaTE4bmV4dCc7XG5pbXBvcnQgeyBGZWlkZVVzZXJBcGlUeXBlIH0gZnJvbSAnLi9hcGlUeXBlcyc7XG5pbXBvcnQgeyBwYXJzZVVzZXJPYmplY3QgfSBmcm9tICcuL3BhcnNlVXNlck9iamVjdCc7XG5cbmNvbnN0IEluZm9MaXN0ID0gc3R5bGVkLnVsYFxuICBwYWRkaW5nOiAwIDAgMCAke3NwYWNpbmcubm9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gICAgICAgICAgICAgIHJldHVybiAoXG4gICAgICAgICAgICAgICAgICA8bGkga2V5PXtncm91cFR5cGV9PlxuICAgICAgICAgICAgICAgICAgICB7dChgdXNlci5ncm91cFR5cGVzLiR7Z3JvdXBUeXBlfWApfVxuICAgICAgICAgICAgICAgICAgICA8SW5mb0xpc3Q+XG4gICAgICAgICAgICAgICAgICAgICAge3ZhbC5tYXAoKGdyb3VwKSA9PiAoXG4gICAgICAgICAgICAgICAgICAgICAgICA8bGkga2V5PXtncm91cC5pZH0+e2Ake2dyb3VwLmRpc3BsYXlOYW1lfSR7Z3JvdXAuZ3JlcCA/IGAgKCR7Z3JvdXAuZ3JlcC5jb2RlfSlgIDogJyd9YH08L2xpPlxuICAgICAgICAgICAgICAgICAgICAgICkpfVxuICAgICAgICAgICAgICAgICAgICA8L0luZm9MaXN0PlxuICAgICAgICAgICAgICAgICAgPC9saT5cbiAgICAgICAgICAgICAgICApO1xuICAgICAgICAgICAgICB9KX1cbiAgICAgICAgICAgIDwvSW5mb0xpc3Q+XG4gICAgICAgICAgPC9saT5cbiAgICAgICAgKSl9XG4gICAgICA8L0luZm9MaXN0PlxuICAgICAge3BhcnNlZFVzZXIuZ3JlcENvZGVzLmxlbmd0aCA+IDAgJiYgKFxuICAgICAgICA8SW5mb0xpc3QgZGF0YS1oai1zdXBwcmVzcz5cbiAgICAgICAgICA8bGkga2V5PVwiZ3JlcENvZGVzXCI+XG4gICAgICAgICAgICB7dCgndXNlci5ncm91cFR5cGVzLmdyZXBDb2RlJyl9XG4gICAgICAgICAgICA8SW5mb0xpc3Q+XG4gICAgICAgICAgICAgIHtwYXJzZWRVc2VyLmdyZXBDb2Rlcy5tYXAoKGNvZGUpID0+IChcbiAgICAgICAgICAgICAgICA8bGkga2V5PXtjb2RlLmlkfT57YCR7Y29kZS5kaXNwbGF5TmFtZX0gKCR7Y29kZS5jb2RlfSlgfTwvbGk+XG4gICAgICAgICAgICAgICkpfVxuICAgICAgICAgICAgPC9JbmZvTGlzdD5cbiAgICAgICAgICA8L2xpPlxuICAgICAgICA8L0luZm9MaXN0PlxuICAgICAgKX1cbiAgICA8L2Rpdj5cbiAgKTtcbn07XG4iXX0= */"));
25
- var ShortInfoDiv = /*#__PURE__*/_styled("div", {
26
- target: "egwtjgg0",
27
- label: "ShortInfoDiv"
28
- })(process.env.NODE_ENV === "production" ? {
29
- name: "xsvpxu",
30
- styles: "margin:2rem auto"
31
- } : {
32
- name: "xsvpxu",
33
- styles: "margin:2rem auto",
34
- map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIlVzZXJJbmZvLnRzeCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFxQitCIiwiZmlsZSI6IlVzZXJJbmZvLnRzeCIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogQ29weXJpZ2h0IChjKSAyMDIyLXByZXNlbnQsIE5ETEEuXG4gKlxuICogVGhpcyBzb3VyY2UgY29kZSBpcyBsaWNlbnNlZCB1bmRlciB0aGUgR1BMdjMgbGljZW5zZSBmb3VuZCBpbiB0aGVcbiAqIExJQ0VOU0UgZmlsZSBpbiB0aGUgcm9vdCBkaXJlY3Rvcnkgb2YgdGhpcyBzb3VyY2UgdHJlZS5cbiAqL1xuXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCc7XG5pbXBvcnQgeyBzcGFjaW5nIH0gZnJvbSAnQG5kbGEvY29yZSc7XG5pbXBvcnQgeyB1c2VUcmFuc2xhdGlvbiB9IGZyb20gJ3JlYWN0LWkxOG5leHQnO1xuaW1wb3J0IHsgRmVpZGVVc2VyQXBpVHlwZSB9IGZyb20gJy4vYXBpVHlwZXMnO1xuaW1wb3J0IHsgcGFyc2VVc2VyT2JqZWN0IH0gZnJvbSAnLi9wYXJzZVVzZXJPYmplY3QnO1xuXG5jb25zdCBJbmZvTGlzdCA9IHN0eWxlZC51bGBcbiAgcGFkZG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+XG4gICAgICAgIDwvZGl2PlxuICAgICAgICA8ZGl2IGRhdGEtaGotc3VwcHJlc3M+XG4gICAgICAgICAge3QoJ3VzZXIubWFpbCcpfTogPGI+e3VzZXIubWFpbD8uam9pbignLCAnKX08L2I+XG4gICAgICAgIDwvZGl2PlxuICAgICAgICB7dXNlci5wcmVmZXJyZWRMYW5ndWFnZSAmJiAoXG4gICAgICAgICAgPGRpdiBkYXRhLWhqLXN1cHByZXNzPlxuICAgICAgICAgICAge3QoJ3VzZXIucHJlZmVycmVkTGFuZ3VhZ2UnKX06IDxiPnt0KGBsYW5ndWFnZXMuJHt1c2VyLnByZWZlcnJlZExhbmd1YWdlfWApfTwvYj5cbiAgICAgICAgICA8L2Rpdj5cbiAgICAgICAgKX1cbiAgICAgICAge3VzZXIubW9iaWxlICYmIChcbiAgICAgICAgICA8ZGl2IGRhdGEtaGotc3VwcHJlc3M+XG4gICAgICAgICAgICB7dCgndXNlci5tb2JpbGUnKX06IDxiPnt1c2VyLm1vYmlsZX08L2I+XG4gICAgICAgICAgPC9kaXY+XG4gICAgICAgICl9XG4gICAgICA8L1Nob3J0SW5mb0Rpdj5cblxuICAgICAgPEluZm9MaXN0IGRhdGEtaGotc3VwcHJlc3M+XG4gICAgICAgIHtwYXJzZWRVc2VyLm9yZ2FuaXphdGlvbnMubWFwKChvcmcpID0+IChcbiAgICAgICAgICA8bGkga2V5PXtvcmcuaWR9PlxuICAgICAgICAgICAge2Ake29yZy5kaXNwbGF5TmFtZX0ke29yZy5tZW1iZXJzaGlwLnByaW1hcnlTY2hvb2wgPyBgICgke3QoJ3VzZXIucHJpbWFyeVNjaG9vbCcpfSlgIDogJyd9YH1cbiAgICAgICAgICAgIDxJbmZvTGlzdD5cbiAgICAgICAgICAgICAge09iamVjdC5lbnRyaWVzKG9yZy5jaGlsZHJlbikubWFwKChbZ3JvdXBUeXBlLCB2YWxdKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKHZhbC5sZW5ndGggPCAxKSByZXR1cm4gbnVsbDtcbiAgICAgICAgICAgICAgICByZXR1cm4gKFxuICAgICAgICAgICAgICAgICAgPGxpIGtleT17Z3JvdXBUeXBlfT5cbiAgICAgICAgICAgICAgICAgICAge3QoYHVzZXIuZ3JvdXBUeXBlcy4ke2dyb3VwVHlwZX1gKX1cbiAgICAgICAgICAgICAgICAgICAgPEluZm9MaXN0PlxuICAgICAgICAgICAgICAgICAgICAgIHt2YWwubWFwKChncm91cCkgPT4gKFxuICAgICAgICAgICAgICAgICAgICAgICAgPGxpIGtleT17Z3JvdXAuaWR9PntgJHtncm91cC5kaXNwbGF5TmFtZX0ke2dyb3VwLmdyZXAgPyBgICgke2dyb3VwLmdyZXAuY29kZX0pYCA6ICcnfWB9PC9saT5cbiAgICAgICAgICAgICAgICAgICAgICApKX1cbiAgICAgICAgICAgICAgICAgICAgPC9JbmZvTGlzdD5cbiAgICAgICAgICAgICAgICAgIDwvbGk+XG4gICAgICAgICAgICAgICAgKTtcbiAgICAgICAgICAgICAgfSl9XG4gICAgICAgICAgICA8L0luZm9MaXN0PlxuICAgICAgICAgIDwvbGk+XG4gICAgICAgICkpfVxuICAgICAgPC9JbmZvTGlzdD5cbiAgICAgIHtwYXJzZWRVc2VyLmdyZXBDb2Rlcy5sZW5ndGggPiAwICYmIChcbiAgICAgICAgPEluZm9MaXN0IGRhdGEtaGotc3VwcHJlc3M+XG4gICAgICAgICAgPGxpIGtleT1cImdyZXBDb2Rlc1wiPlxuICAgICAgICAgICAge3QoJ3VzZXIuZ3JvdXBUeXBlcy5ncmVwQ29kZScpfVxuICAgICAgICAgICAgPEluZm9MaXN0PlxuICAgICAgICAgICAgICB7cGFyc2VkVXNlci5ncmVwQ29kZXMubWFwKChjb2RlKSA9PiAoXG4gICAgICAgICAgICAgICAgPGxpIGtleT17Y29kZS5pZH0+e2Ake2NvZGUuZGlzcGxheU5hbWV9ICgke2NvZGUuY29kZX0pYH08L2xpPlxuICAgICAgICAgICAgICApKX1cbiAgICAgICAgICAgIDwvSW5mb0xpc3Q+XG4gICAgICAgICAgPC9saT5cbiAgICAgICAgPC9JbmZvTGlzdD5cbiAgICAgICl9XG4gICAgPC9kaXY+XG4gICk7XG59O1xuIl19 */",
35
- toString: _EMOTION_STRINGIFIED_CSS_ERROR__
36
- });
37
- var isTeacher = function isTeacher(affiliations) {
38
- return affiliations.includes('employee');
39
- };
40
- export var UserInfo = function UserInfo(_ref) {
41
- var _user$mail;
42
- var user = _ref.user;
43
- var _useTranslation = useTranslation(),
44
- t = _useTranslation.t;
45
- var parsedUser = parseUserObject(user);
46
- return _jsxs("div", {
47
- children: [_jsx("p", {
48
- children: t('user.loggedInAs', {
49
- role: t("user.role.".concat(isTeacher(parsedUser.eduPersonAffiliation) ? 'employee' : 'student'))
50
- })
51
- }), _jsxs(ShortInfoDiv, {
52
- children: [_jsxs("div", {
53
- "data-hj-suppress": true,
54
- children: [t('user.username'), ": ", _jsx("b", {
55
- children: user.uid
56
- })]
57
- }), _jsxs("div", {
58
- "data-hj-suppress": true,
59
- children: [t('user.name'), ": ", _jsx("b", {
60
- children: user.displayName
61
- })]
62
- }), _jsxs("div", {
63
- "data-hj-suppress": true,
64
- children: [t('user.mail'), ": ", _jsx("b", {
65
- children: (_user$mail = user.mail) === null || _user$mail === void 0 ? void 0 : _user$mail.join(', ')
66
- })]
67
- }), user.preferredLanguage && _jsxs("div", {
68
- "data-hj-suppress": true,
69
- children: [t('user.preferredLanguage'), ": ", _jsx("b", {
70
- children: t("languages.".concat(user.preferredLanguage))
71
- })]
72
- }), user.mobile && _jsxs("div", {
73
- "data-hj-suppress": true,
74
- children: [t('user.mobile'), ": ", _jsx("b", {
75
- children: user.mobile
76
- })]
77
- })]
78
- }), _jsx(InfoList, {
79
- "data-hj-suppress": true,
80
- children: parsedUser.organizations.map(function (org) {
81
- return _jsxs("li", {
82
- children: ["".concat(org.displayName).concat(org.membership.primarySchool ? " (".concat(t('user.primarySchool'), ")") : ''), _jsx(InfoList, {
83
- children: Object.entries(org.children).map(function (_ref2) {
84
- var _ref3 = _slicedToArray(_ref2, 2),
85
- groupType = _ref3[0],
86
- val = _ref3[1];
87
- if (val.length < 1) return null;
88
- return _jsxs("li", {
89
- children: [t("user.groupTypes.".concat(groupType)), _jsx(InfoList, {
90
- children: val.map(function (group) {
91
- return _jsx("li", {
92
- children: "".concat(group.displayName).concat(group.grep ? " (".concat(group.grep.code, ")") : '')
93
- }, group.id);
94
- })
95
- })]
96
- }, groupType);
97
- })
98
- })]
99
- }, org.id);
100
- })
101
- }), parsedUser.grepCodes.length > 0 && _jsx(InfoList, {
102
- "data-hj-suppress": true,
103
- children: _jsxs("li", {
104
- children: [t('user.groupTypes.grepCode'), _jsx(InfoList, {
105
- children: parsedUser.grepCodes.map(function (code) {
106
- return _jsx("li", {
107
- children: "".concat(code.displayName, " (").concat(code.code, ")")
108
- }, code.id);
109
- })
110
- })]
111
- }, "grepCodes")
112
- })]
113
- });
114
- };
@@ -1 +0,0 @@
1
- export {};
package/es/User/index.js DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Copyright (c) 2021-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 { UserInfo } from './UserInfo';
10
- export { UserInfo };