@applicaster/zapp-react-native-ui-components 16.0.0-rc.33 → 16.0.0-rc.35

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 (26) hide show
  1. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +47 -21
  2. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +34 -6
  3. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -3
  4. package/Components/MasterCell/DefaultComponents/PressableView.tsx +29 -9
  5. package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +4 -0
  6. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +154 -100
  7. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +15 -4
  8. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +56 -22
  9. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +6 -4
  10. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +3 -1
  11. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +32 -21
  12. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +15 -4
  13. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +23 -16
  14. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +8 -3
  15. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +2 -2
  16. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/insertButtonsBetweenLabels.test.ts +45 -13
  17. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +2 -2
  18. package/Components/MasterCell/contexts/PressedStateContext.ts +3 -0
  19. package/Components/MasterCell/hooks/index.ts +2 -0
  20. package/Components/MasterCell/hooks/usePressedState.ts +4 -0
  21. package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +332 -0
  22. package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +402 -0
  23. package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +811 -0
  24. package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +878 -0
  25. package/Components/ModalComponent/AudioPlayer/Components/index.ts +7 -0
  26. package/package.json +5 -5
@@ -1,4 +1,7 @@
1
- import { toNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
1
+ import {
2
+ toNumberWithDefault,
3
+ toNumberWithDefaultZero,
4
+ } from "@applicaster/zapp-react-native-utils/numberUtils";
2
5
  import { compact } from "@applicaster/zapp-react-native-utils/cellUtils";
3
6
 
4
7
  import { Asset } from "./Asset";
@@ -10,23 +13,37 @@ import {
10
13
  getPressableStyles,
11
14
  getTextLabelStyles,
12
15
  } from "./utils";
16
+ import { ViewStyle } from "react-native";
17
+ import { Spacer } from "./Spacer";
13
18
 
14
- const displayModeStyle = (value) => {
19
+ const displayModeStyle = (value, isVertical: boolean) => {
15
20
  const mode = value("display_mode") || "dynamic";
16
21
 
17
- if (mode === "fixed") {
18
- return {
19
- width: toNumberWithDefault(140, value("width")),
20
- };
21
- }
22
+ const defaultStyle = {
23
+ flexShrink: 1,
24
+ };
22
25
 
23
- if (mode === "fill") {
24
- return {
25
- flex: 1,
26
- };
27
- }
26
+ const width = toNumberWithDefault(140, value("width"));
28
27
 
29
- return {};
28
+ switch (mode) {
29
+ case "fixed":
30
+ return {
31
+ ...defaultStyle,
32
+ width,
33
+ maxWidth: width,
34
+ };
35
+ case "fill":
36
+ return {
37
+ ...defaultStyle,
38
+ width: isVertical ? "100%" : undefined,
39
+ flex: !isVertical ? 1 : undefined,
40
+ };
41
+ case "dynamic":
42
+ default:
43
+ return {
44
+ ...defaultStyle,
45
+ };
46
+ }
30
47
  };
31
48
 
32
49
  type Props = {
@@ -34,7 +51,8 @@ type Props = {
34
51
  value: Function;
35
52
  stylePrefix: string;
36
53
  specificPrefix: string;
37
- spacingStyle: Record<string, unknown>;
54
+ spacingStyle: ViewStyle;
55
+ isVertical: boolean;
38
56
  };
39
57
 
40
58
  export const Button = ({
@@ -43,8 +61,9 @@ export const Button = ({
43
61
  stylePrefix,
44
62
  specificPrefix,
45
63
  spacingStyle,
64
+ isVertical,
46
65
  }: Props) => {
47
- // Retrives values depending to the slot
66
+ // Retrieves values depending to the slot
48
67
  const getSlotBasedValue = (property: string) =>
49
68
  value(`${specificPrefix}_${property}`);
50
69
 
@@ -68,21 +87,30 @@ export const Button = ({
68
87
  const testID = `mobile_action_button_${index + 1}`;
69
88
  const actionIdentifier = getSlotBasedValue("assign_action");
70
89
  const assetAlignment = getValue("asset_alignment") || "left";
90
+
91
+ const hasHorizontalAlignment = ["left", "right"].includes(assetAlignment);
92
+ const vGutter = toNumberWithDefaultZero(getValue("vertical_gutter"));
93
+ const hGutter = toNumberWithDefaultZero(getValue("horizontal_gutter"));
71
94
  const actionAssetFlavour = getValue("action_asset_flavour");
72
95
  const contentsAlignment = getValue("contents_alignment") || "center";
96
+ const displayMode = getValue("display_mode") || "dynamic";
73
97
 
74
98
  return {
75
99
  type: "MobileActionButton",
76
100
  style: {
77
- flexDirection: getContentDirection(assetAlignment),
78
- alignContent: "center",
79
- alignItems: getContentsAlignment(contentsAlignment, assetAlignment),
80
- justifyContent: getContentsAlignment(contentsAlignment, assetAlignment),
101
+ // alignContent: "center", Why do we need this?
81
102
  ...getPressableStyles(getValue),
82
- ...displayModeStyle(getValue),
103
+ ...displayModeStyle(getValue, isVertical),
83
104
  ...spacingStyle,
84
105
  },
85
106
  additionalProps: {
107
+ displayMode,
108
+ alignment: {
109
+ alignContent: "center",
110
+ flexDirection: getContentDirection(assetAlignment),
111
+ alignItems: getContentsAlignment(contentsAlignment, assetAlignment),
112
+ justifyContent: getContentsAlignment(contentsAlignment, assetAlignment),
113
+ },
86
114
  action: {
87
115
  identifier: actionIdentifier,
88
116
  flavour: actionAssetFlavour,
@@ -102,7 +130,12 @@ export const Button = ({
102
130
  testID,
103
131
  })
104
132
  : null,
105
-
133
+ Spacer({
134
+ enabled: assetEnabled && labelEnabled,
135
+ style: hasHorizontalAlignment
136
+ ? { width: hGutter }
137
+ : { height: vGutter },
138
+ }),
106
139
  labelEnabled
107
140
  ? TextLabelsContainer({
108
141
  style: getTextLabelStyles(getValue),
@@ -114,7 +147,8 @@ export const Button = ({
114
147
  color: getValue("focused_font_color"),
115
148
  },
116
149
  transformText: getValue("text_transform") || "default",
117
- numberOfLines: getValue("number_of_lines"),
150
+ numberOfLines: getValue("number_of_lines") || 1,
151
+ ellipsizeMode: "tail",
118
152
  },
119
153
  actionIdentifier,
120
154
  testID,
@@ -1,16 +1,18 @@
1
1
  type Props = {
2
2
  enabled?: boolean;
3
+ style?: object;
3
4
  };
4
5
 
5
- export const Spacer = ({ enabled = false }: Props = {}) => {
6
+ export const Spacer = ({
7
+ enabled = false,
8
+ style = { flex: 1 },
9
+ }: Props = {}) => {
6
10
  if (!enabled) {
7
11
  return null;
8
12
  }
9
13
 
10
14
  return {
11
15
  type: "View",
12
- style: {
13
- flex: 1,
14
- },
16
+ style,
15
17
  };
16
18
  };
@@ -14,6 +14,9 @@ export const TextLabelsContainer = ({
14
14
  }: Props) => {
15
15
  return {
16
16
  type: "View",
17
+ style: {
18
+ flexShrink: 1,
19
+ },
17
20
  additionalProps: {
18
21
  mobileActionRole: "label_container",
19
22
  },
@@ -26,7 +29,6 @@ export const TextLabelsContainer = ({
26
29
  context: actionIdentifier,
27
30
  name: "label_1",
28
31
  },
29
- state: "default",
30
32
  mobileActionRole: "label",
31
33
  testID: testID ? `${testID}-label` : undefined,
32
34
  ...extraProps,
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { Text as RNText, TouchableOpacity, View } from "react-native";
2
+ import { Pressable, Text as RNText, View } from "react-native";
3
3
  import { render, fireEvent } from "@testing-library/react-native";
4
4
  import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
5
5
 
@@ -8,6 +8,11 @@ import { elementMapper } from "../../../../elementMapper";
8
8
  import { defaultComponents } from "../../../index";
9
9
  import { MobileActionButtons } from "..";
10
10
  import { AssetComponent } from "../AssetComponent";
11
+ import { usePressedState } from "../../../../hooks/usePressedState";
12
+
13
+ jest.mock("../../../../hooks/usePressedState", () => ({
14
+ usePressedState: jest.fn(),
15
+ }));
11
16
 
12
17
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/actions", () => ({
13
18
  useActions: jest.fn(),
@@ -136,6 +141,7 @@ const baseNode = {
136
141
  borderColor: "rgba(4,4,4,1)",
137
142
  },
138
143
  testID: "mobile-action-button",
144
+ testOnly_pressed: false,
139
145
  },
140
146
  elements: [
141
147
  {
@@ -190,14 +196,20 @@ const baseNode = {
190
196
  describe("MobileActionButton", () => {
191
197
  beforeEach(() => {
192
198
  jest.clearAllMocks();
199
+ (usePressedState as jest.Mock).mockReturnValue(false);
193
200
  });
194
201
 
195
- const renderNode = (node = baseNode) =>
196
- render(
202
+ const renderNode = ({ node = baseNode, pressed = false } = {}) => {
203
+ if (pressed) {
204
+ node.props.testOnly_pressed = true;
205
+ }
206
+
207
+ return render(
197
208
  <React.Fragment>
198
209
  {elementMapper(defaultComponents)(node as never)}
199
210
  </React.Fragment>
200
211
  );
212
+ };
201
213
 
202
214
  it("renders nested image and text children through elementMapper", () => {
203
215
  mockUseActions.mockReturnValue(buildActionContext());
@@ -210,12 +222,13 @@ describe("MobileActionButton", () => {
210
222
  });
211
223
 
212
224
  it("applies focused styles when action entry state is active", () => {
225
+ (usePressedState as jest.Mock).mockReturnValue(true);
213
226
  mockUseActions.mockReturnValue(buildActionContext({ active: true }));
214
227
 
215
- const { getByTestId, getByText } = renderNode();
228
+ const { getByTestId, getByText } = renderNode({ pressed: true });
216
229
 
217
230
  expect(
218
- getByTestId("mobile-action-button").props.style.backgroundColor
231
+ getByTestId("mobile-action-button").props.style[2].backgroundColor
219
232
  ).toBe("rgba(3,3,3,1)");
220
233
 
221
234
  expect(getByText("Play").props.style).toEqual(
@@ -253,6 +266,8 @@ describe("MobileActionButton", () => {
253
266
  })
254
267
  );
255
268
 
269
+ node.props.testOnly_pressed = false;
270
+
256
271
  const { UNSAFE_getAllByType, UNSAFE_getByType, getByTestId, getByText } =
257
272
  render(
258
273
  <React.Fragment>
@@ -260,14 +275,14 @@ describe("MobileActionButton", () => {
260
275
  </React.Fragment>
261
276
  );
262
277
 
263
- const pressable = UNSAFE_getByType(TouchableOpacity);
278
+ const pressable = UNSAFE_getByType(Pressable);
264
279
  const label = getByText("Play");
265
280
  const asset = getByTestId("mobile_action_button_1-asset");
266
281
 
267
282
  expect(pressable.props.testID).toBe("mobile_action_button_1");
268
283
  expect(pressable.props.accessibilityLabel).toBe("entry-1");
269
284
 
270
- expect(pressable.props.style).toMatchObject({
285
+ expect(pressable.props.style({ pressed: false })[0]).toMatchObject({
271
286
  backgroundColor: "rgba(1,1,1,1)",
272
287
  borderColor: "rgba(2,2,2,1)",
273
288
  borderWidth: 1,
@@ -278,15 +293,11 @@ describe("MobileActionButton", () => {
278
293
  height: 24,
279
294
  });
280
295
 
281
- expect(label.props.style).toEqual(
282
- expect.arrayContaining([
283
- expect.objectContaining({
284
- color: "rgba(10,10,10,1)",
285
- fontSize: 15,
286
- lineHeight: 24,
287
- }),
288
- ])
289
- );
296
+ expect(label.props.style[0]).toMatchObject({
297
+ color: "rgba(10,10,10,1)",
298
+ fontSize: 15,
299
+ lineHeight: 24,
300
+ });
290
301
 
291
302
  expect(UNSAFE_getAllByType(View).length).toBeGreaterThan(0);
292
303
  expect(UNSAFE_getAllByType(RNText).length).toBeGreaterThan(0);
@@ -324,7 +335,7 @@ describe("MobileActionButton", () => {
324
335
  buildActionContext({ mobileButtonAssets: MockAssetComponent })
325
336
  );
326
337
 
327
- const { getByTestId } = renderNode(nodeWithFlavour1);
338
+ const { getByTestId } = renderNode({ node: nodeWithFlavour1 });
328
339
 
329
340
  expect(MockAssetComponent).toHaveBeenCalled();
330
341
  expect(getByTestId("mobile-action-button-asset")).toBeTruthy();
@@ -339,7 +350,7 @@ describe("MobileActionButton", () => {
339
350
  buildActionContext({ mobileButtonAssets: MockAssetComponent })
340
351
  );
341
352
 
342
- renderNode(nodeWithFlavour1);
353
+ renderNode({ node: nodeWithFlavour1 });
343
354
 
344
355
  expect(MockAssetComponent).toHaveBeenCalledWith(
345
356
  expect.objectContaining({ flavour: "flavour_1" }),
@@ -356,7 +367,7 @@ describe("MobileActionButton", () => {
356
367
  buildActionContext({ mobileButtonAssets: MockAssetComponent })
357
368
  );
358
369
 
359
- renderNode(nodeWithFlavour2);
370
+ renderNode({ node: nodeWithFlavour2 });
360
371
 
361
372
  expect(MockAssetComponent).toHaveBeenCalledWith(
362
373
  expect.objectContaining({ flavour: "flavour_2" }),
@@ -369,7 +380,7 @@ describe("MobileActionButton", () => {
369
380
  buildActionContext({ mobileButtonAssets: undefined })
370
381
  );
371
382
 
372
- const { queryByTestId } = renderNode(nodeWithFlavour1);
383
+ const { queryByTestId } = renderNode({ node: nodeWithFlavour1 });
373
384
 
374
385
  expect(queryByTestId("mobile-action-button-asset")).toBeNull();
375
386
  });
@@ -385,7 +396,7 @@ describe("MobileActionButton", () => {
385
396
  })
386
397
  );
387
398
 
388
- const { getByTestId } = renderNode(nodeWithFlavour1);
399
+ const { getByTestId } = renderNode({ node: nodeWithFlavour1 });
389
400
 
390
401
  expect(getByTestId("mobile-action-button-asset")).toBeTruthy();
391
402
  });
@@ -241,10 +241,21 @@ describe("MobileActionButtons", () => {
241
241
  expect(overImageResult?.additionalProps?.contentStyle).toMatchObject({
242
242
  flexDirection: "column",
243
243
  alignItems: "center",
244
- marginTop: 5,
245
- marginRight: 6,
246
- marginBottom: 7,
247
- marginLeft: 8,
244
+ paddingTop: 5,
245
+ paddingRight: 6,
246
+ paddingBottom: 7,
247
+ paddingLeft: 8,
248
+ });
249
+
250
+ expect(overImageResult?.style).toMatchObject({
251
+ alignItems: "flex-end",
252
+ bottom: 0,
253
+ justifyContent: "flex-start",
254
+ left: 0,
255
+ position: "absolute",
256
+ right: 0,
257
+ top: 0,
258
+ zIndex: 10,
248
259
  });
249
260
 
250
261
  expect(
@@ -6,6 +6,7 @@ import {
6
6
  } from "./utils";
7
7
  import { Button } from "./Button";
8
8
  import { buildActionButtonsModel } from "../../ActionButtonsCore/model";
9
+ import { ViewStyle } from "react-native";
9
10
 
10
11
  const CONTAINER_PREFIX = "mobile_buttons_container";
11
12
  const BUTTON_PREFIX = "mobile_button";
@@ -42,9 +43,24 @@ export const MobileActionButtons = ({
42
43
  return null;
43
44
  }
44
45
 
46
+ const {
47
+ container: { stacking, verticalGutter, horizontalGutter },
48
+ } = model;
49
+
50
+ const isVertical = stacking === "vertical";
51
+ const isOverImage = position === "over_image";
52
+ const gutter = isVertical ? verticalGutter : horizontalGutter;
53
+
54
+ const containerPaddings = {
55
+ paddingTop: model.container.margins.top,
56
+ paddingRight: model.container.margins.right,
57
+ paddingBottom: model.container.margins.bottom,
58
+ paddingLeft: model.container.margins.left,
59
+ };
60
+
45
61
  const style = {
46
62
  alignItems: "center",
47
- ...(placement === "over_image"
63
+ ...(isOverImage
48
64
  ? {
49
65
  position: "absolute",
50
66
  zIndex: 10,
@@ -60,28 +76,18 @@ export const MobileActionButtons = ({
60
76
  };
61
77
 
62
78
  const contentStyle = {
63
- flexDirection: model.container.stacking === "vertical" ? "column" : "row",
64
- alignSelf:
65
- placement !== "over_image" ? model.container.horizontalAlign : undefined,
79
+ ...containerPaddings,
80
+ flexDirection: isVertical ? "column" : "row",
81
+ width: isVertical ? "100%" : undefined,
82
+ alignSelf: !isOverImage ? model.container.horizontalAlign : undefined,
66
83
  alignItems: model.container.horizontalAlign,
67
- marginTop: model.container.margins.top,
68
- marginRight: model.container.margins.right,
69
- marginBottom: model.container.margins.bottom,
70
- marginLeft: model.container.margins.left,
71
84
  };
72
85
 
73
86
  const elements = compact(
74
87
  model.buttons.map(({ renderIndex, specificPrefix, stylePrefix }) => {
75
88
  const isNotLast = renderIndex < model.buttons.length - 1;
76
89
 
77
- const {
78
- container: { stacking, verticalGutter, horizontalGutter },
79
- } = model;
80
-
81
- const isVertical = stacking === "vertical";
82
- const gutter = isVertical ? verticalGutter : horizontalGutter;
83
-
84
- const spacingStyle = {
90
+ const spacingStyle: ViewStyle = {
85
91
  [isVertical ? "marginBottom" : "marginRight"]: isNotLast ? gutter : 0,
86
92
  };
87
93
 
@@ -91,6 +97,7 @@ export const MobileActionButtons = ({
91
97
  stylePrefix,
92
98
  specificPrefix,
93
99
  spacingStyle,
100
+ isVertical,
94
101
  });
95
102
 
96
103
  if (!button) return null;
@@ -5,14 +5,19 @@ import {
5
5
  } from "..";
6
6
 
7
7
  describe("mobile action insertion helpers", () => {
8
- const labels = [{ name: "text_label_1" }, { name: "text_label_2" }];
8
+ const slots = [
9
+ { name: "text_label_1", element: { type: "View", id: "text_label_1" } },
10
+ { name: "text_label_2", element: { type: "View", id: "text_label_2" } },
11
+ ];
12
+
13
+ const labels = slots.map((slot) => slot.element);
9
14
  const buttons = { type: "View", name: "buttons" };
10
15
 
11
16
  it("inserts label buttons below target label", () => {
12
17
  const result = insertButtonsBetweenLabels(
13
18
  { mobile_buttons_container_position: "below_text_label_1" },
14
19
  buttons,
15
- labels
20
+ slots
16
21
  );
17
22
 
18
23
  expect(result).toEqual([labels[0], buttons, labels[1]]);
@@ -22,7 +27,7 @@ describe("mobile action insertion helpers", () => {
22
27
  const result = insertButtonsBetweenLabels(
23
28
  { mobile_buttons_container_position: "unknown" },
24
29
  buttons,
25
- labels
30
+ slots
26
31
  );
27
32
 
28
33
  expect(result).toEqual([labels[0], labels[1]]);
@@ -8,7 +8,7 @@ import { Platform } from "react-native";
8
8
  export const insertButtonsBetweenLabels = (
9
9
  configuration: Record<string, unknown>,
10
10
  buttons,
11
- labels = []
11
+ slots = [] // { name, element } per canonical text label slot
12
12
  ) =>
13
13
  insertBetweenLabels(
14
14
  {
@@ -19,7 +19,7 @@ export const insertButtonsBetweenLabels = (
19
19
  appendWhenMissing: false,
20
20
  },
21
21
  buttons,
22
- labels // "text_label_1", "text_label_2", "text_label_3", "text_label_4"
22
+ slots
23
23
  );
24
24
 
25
25
  export const insertButtonsBetweenLabelContainers = (
@@ -3,18 +3,20 @@ import { insertButtonsBetweenLabels } from "..";
3
3
  describe("insertButtonsBetweenLabels - depthlevel 1", () => {
4
4
  const buttons = "buttons";
5
5
 
6
- const labels = [
7
- { name: "label_1" },
8
- { name: "label_2" },
9
- { name: "label_3" },
6
+ const slots = [
7
+ { name: "label_1", element: { id: "label_1" } },
8
+ { name: "label_2", element: { id: "label_2" } },
9
+ { name: "label_3", element: { id: "label_3" } },
10
10
  ];
11
11
 
12
+ const labels = slots.map((slot) => slot.element);
13
+
12
14
  it("put buttons on top", () => {
13
15
  const configuration = {
14
16
  tv_buttons_container_position: "on_top",
15
17
  };
16
18
 
17
- const result = insertButtonsBetweenLabels(configuration, buttons, labels);
19
+ const result = insertButtonsBetweenLabels(configuration, buttons, slots);
18
20
 
19
21
  expect(result).toEqual([buttons, ...labels]);
20
22
  });
@@ -24,7 +26,7 @@ describe("insertButtonsBetweenLabels - depthlevel 1", () => {
24
26
  tv_buttons_container_position: "unknown_position",
25
27
  };
26
28
 
27
- const result = insertButtonsBetweenLabels(configuration, buttons, labels);
29
+ const result = insertButtonsBetweenLabels(configuration, buttons, slots);
28
30
 
29
31
  expect(result).toEqual([...labels, buttons]);
30
32
  });
@@ -34,7 +36,7 @@ describe("insertButtonsBetweenLabels - depthlevel 1", () => {
34
36
  tv_buttons_container_position: "label_1",
35
37
  };
36
38
 
37
- const result = insertButtonsBetweenLabels(configuration, buttons, labels);
39
+ const result = insertButtonsBetweenLabels(configuration, buttons, slots);
38
40
 
39
41
  expect(result).toEqual([labels[0], buttons, labels[1], labels[2]]);
40
42
  });
@@ -44,7 +46,7 @@ describe("insertButtonsBetweenLabels - depthlevel 1", () => {
44
46
  tv_buttons_container_position: "label_2",
45
47
  };
46
48
 
47
- const result = insertButtonsBetweenLabels(configuration, buttons, labels);
49
+ const result = insertButtonsBetweenLabels(configuration, buttons, slots);
48
50
 
49
51
  expect(result).toEqual([labels[0], labels[1], buttons, labels[2]]);
50
52
  });
@@ -54,22 +56,52 @@ describe("insertButtonsBetweenLabels - depthlevel 1", () => {
54
56
  tv_buttons_container_position: "label_3",
55
57
  };
56
58
 
57
- const result = insertButtonsBetweenLabels(configuration, buttons, labels);
59
+ const result = insertButtonsBetweenLabels(configuration, buttons, slots);
58
60
 
59
61
  expect(result).toEqual([labels[0], labels[1], labels[2], buttons]);
60
62
  });
61
63
 
62
- it("put underneath all", () => {
64
+ it("put above label_2", () => {
65
+ const configuration = {
66
+ tv_buttons_container_position: "above_label_2",
67
+ };
68
+
69
+ const result = insertButtonsBetweenLabels(configuration, buttons, slots);
70
+
71
+ expect(result).toEqual([labels[0], buttons, labels[1], labels[2]]);
72
+ });
73
+
74
+ it("keeps the slot when its label is empty (null element)", () => {
75
+ const slotsWithEmpty = [
76
+ { name: "label_1", element: { id: "label_1" } },
77
+ { name: "label_2", element: null },
78
+ { name: "label_3", element: { id: "label_3" } },
79
+ ];
80
+
81
+ const configuration = {
82
+ tv_buttons_container_position: "above_label_2",
83
+ };
84
+
85
+ const result = insertButtonsBetweenLabels(
86
+ configuration,
87
+ buttons,
88
+ slotsWithEmpty
89
+ );
90
+
91
+ expect(result).toEqual([{ id: "label_1" }, buttons, { id: "label_3" }]);
92
+ });
93
+
94
+ it("appends buttons when the target is unknown", () => {
63
95
  const configuration = {
64
96
  tv_buttons_container_position: "label_X",
65
97
  };
66
98
 
67
- const result = insertButtonsBetweenLabels(configuration, buttons, labels);
99
+ const result = insertButtonsBetweenLabels(configuration, buttons, slots);
68
100
 
69
101
  expect(result).toEqual([labels[0], labels[1], labels[2], buttons]);
70
102
  });
71
103
 
72
- it("put underneath all", () => {
104
+ it("appends buttons when there are no slots", () => {
73
105
  const configuration = {
74
106
  tv_buttons_container_position: "label_X",
75
107
  };
@@ -88,7 +120,7 @@ describe("insertButtonsBetweenLabels - depthlevel 1", () => {
88
120
  tv_buttons_container_position: "label_X",
89
121
  };
90
122
 
91
- const result = insertButtonsBetweenLabels(configuration, null, labels);
123
+ const result = insertButtonsBetweenLabels(configuration, null, slots);
92
124
 
93
125
  expect(result).toEqual(labels);
94
126
  });
@@ -34,7 +34,7 @@ export const memoizedGetPluginIdentifier = memoizee(getPluginIdentifier);
34
34
  export const insertButtonsBetweenLabels = (
35
35
  configuration: Record<string, unknown>,
36
36
  buttons,
37
- labels = []
37
+ slots = [] // { name, element } per canonical text label slot
38
38
  ) =>
39
39
  insertBetweenLabels(
40
40
  {
@@ -45,7 +45,7 @@ export const insertButtonsBetweenLabels = (
45
45
  appendWhenMissing: true,
46
46
  },
47
47
  buttons,
48
- labels
48
+ slots
49
49
  );
50
50
 
51
51
  export const insertButtonsBetweenLabelContainers = (
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+
3
+ export const PressedStateContext = React.createContext<boolean>(false);
@@ -1 +1,3 @@
1
1
  export { useAsyncRendering } from "./useAsyncRendering";
2
+
3
+ export { usePressedState } from "./usePressedState";
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import { PressedStateContext } from "../contexts/PressedStateContext";
3
+
4
+ export const usePressedState = () => React.useContext(PressedStateContext);