@estiva-app/ui 0.107.0 → 0.108.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/dist/FollowSwitch.d.ts +42 -0
- package/dist/FollowSwitch.d.ts.map +1 -0
- package/dist/MembersDialog.d.ts +25 -0
- package/dist/MembersDialog.d.ts.map +1 -1
- package/dist/MembersPill.d.ts +3 -1
- package/dist/MembersPill.d.ts.map +1 -1
- package/dist/WhoFollowsDialog.d.ts +27 -0
- package/dist/WhoFollowsDialog.d.ts.map +1 -0
- package/dist/eslint/index.js +1 -1
- package/dist/eslint/index.js.map +2 -2
- package/dist/eslint/no-native-title.d.ts +1 -1
- package/dist/eslint/no-native-title.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1088 -951
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/registry.json +231 -3
- package/src/FollowSwitch.mdx +64 -0
- package/src/FollowSwitch.stories.tsx +54 -0
- package/src/FollowSwitch.test.tsx +139 -0
- package/src/FollowSwitch.tsx +127 -0
- package/src/MembersDialog.tsx +115 -62
- package/src/MembersPill.tsx +4 -2
- package/src/WhoFollowsDialog.mdx +65 -0
- package/src/WhoFollowsDialog.stories.tsx +40 -0
- package/src/WhoFollowsDialog.tsx +74 -0
- package/src/eslint/no-native-title.ts +1 -1
- package/src/index.ts +2 -0
- package/src/registry/registry.test.ts +6 -6
- package/stories/Choosing.mdx +2 -0
package/package.json
CHANGED
package/registry.json
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
"kind": "package",
|
|
5
5
|
"repo": "estiva-ui",
|
|
6
6
|
"package": "@estiva-app/ui",
|
|
7
|
-
"packageVersion": "0.
|
|
8
|
-
"exports":
|
|
9
|
-
"typeExports":
|
|
7
|
+
"packageVersion": "0.108.0",
|
|
8
|
+
"exports": 250,
|
|
9
|
+
"typeExports": 259,
|
|
10
10
|
"files": null
|
|
11
11
|
},
|
|
12
12
|
"storybook": {
|
|
@@ -4546,6 +4546,97 @@
|
|
|
4546
4546
|
"app": null,
|
|
4547
4547
|
"looks": []
|
|
4548
4548
|
},
|
|
4549
|
+
{
|
|
4550
|
+
"name": "FollowSwitch",
|
|
4551
|
+
"repo": "estiva-ui",
|
|
4552
|
+
"kind": "component",
|
|
4553
|
+
"importPath": "@estiva-app/ui",
|
|
4554
|
+
"sourceFile": "src/FollowSwitch.tsx",
|
|
4555
|
+
"purpose": "How you follow a place, in one button before its title: Not following, Important or All, and back to a group's default when you chose against it.",
|
|
4556
|
+
"purposeFrom": "page",
|
|
4557
|
+
"props": [
|
|
4558
|
+
{
|
|
4559
|
+
"name": "level",
|
|
4560
|
+
"takes": "all | important",
|
|
4561
|
+
"required": true,
|
|
4562
|
+
"note": "What lights for the viewer now: a level, or `undefined` for Not following."
|
|
4563
|
+
},
|
|
4564
|
+
{
|
|
4565
|
+
"name": "label",
|
|
4566
|
+
"takes": "text",
|
|
4567
|
+
"required": true,
|
|
4568
|
+
"note": "The place's name, for the button's accessible name."
|
|
4569
|
+
},
|
|
4570
|
+
{
|
|
4571
|
+
"name": "onChoose",
|
|
4572
|
+
"takes": "a handler",
|
|
4573
|
+
"required": false,
|
|
4574
|
+
"note": "Changes it. While its promise runs the button waits; a rejection is the caller's to report."
|
|
4575
|
+
},
|
|
4576
|
+
{
|
|
4577
|
+
"name": "readOnlyReason",
|
|
4578
|
+
"takes": "text",
|
|
4579
|
+
"required": false,
|
|
4580
|
+
"note": "Without `onChoose`: why it cannot be changed, said under the pointer (\"This team is archived\")."
|
|
4581
|
+
},
|
|
4582
|
+
{
|
|
4583
|
+
"name": "people",
|
|
4584
|
+
"takes": "true/false",
|
|
4585
|
+
"required": false,
|
|
4586
|
+
"note": "People rather than circles, as `LevelIcon`'s `people`."
|
|
4587
|
+
},
|
|
4588
|
+
{
|
|
4589
|
+
"name": "offDescription",
|
|
4590
|
+
"takes": "text",
|
|
4591
|
+
"required": false,
|
|
4592
|
+
"note": "The line under Not following."
|
|
4593
|
+
},
|
|
4594
|
+
{
|
|
4595
|
+
"name": "backTo",
|
|
4596
|
+
"takes": "text",
|
|
4597
|
+
"required": false,
|
|
4598
|
+
"note": "The name of the group whose default reaches the viewer, when they chose against it: offers \"Back to <name>’s default\"."
|
|
4599
|
+
}
|
|
4600
|
+
],
|
|
4601
|
+
"variants": [
|
|
4602
|
+
{
|
|
4603
|
+
"prop": "level",
|
|
4604
|
+
"values": [
|
|
4605
|
+
"all",
|
|
4606
|
+
"important"
|
|
4607
|
+
]
|
|
4608
|
+
}
|
|
4609
|
+
],
|
|
4610
|
+
"ownsBehaviours": [
|
|
4611
|
+
{
|
|
4612
|
+
"id": "portal",
|
|
4613
|
+
"behaviour": "Floats on top of the page"
|
|
4614
|
+
},
|
|
4615
|
+
{
|
|
4616
|
+
"id": "press-outside",
|
|
4617
|
+
"behaviour": "Closes on a press outside"
|
|
4618
|
+
},
|
|
4619
|
+
{
|
|
4620
|
+
"id": "page-keys",
|
|
4621
|
+
"behaviour": "Takes its keys by itself"
|
|
4622
|
+
},
|
|
4623
|
+
{
|
|
4624
|
+
"id": "focus",
|
|
4625
|
+
"behaviour": "Holds focus inside while open, and gives it back"
|
|
4626
|
+
},
|
|
4627
|
+
{
|
|
4628
|
+
"id": "follow",
|
|
4629
|
+
"behaviour": "Stays attached to its anchor on scroll and resize"
|
|
4630
|
+
}
|
|
4631
|
+
],
|
|
4632
|
+
"status": "stable",
|
|
4633
|
+
"migrationStage": null,
|
|
4634
|
+
"docsId": "people-followswitch--docs",
|
|
4635
|
+
"storyId": "people-followswitch--important",
|
|
4636
|
+
"docPage": "src/FollowSwitch.mdx",
|
|
4637
|
+
"app": null,
|
|
4638
|
+
"looks": []
|
|
4639
|
+
},
|
|
4549
4640
|
{
|
|
4550
4641
|
"name": "Form",
|
|
4551
4642
|
"repo": "estiva-ui",
|
|
@@ -5670,6 +5761,46 @@
|
|
|
5670
5761
|
"app": null,
|
|
5671
5762
|
"looks": []
|
|
5672
5763
|
},
|
|
5764
|
+
{
|
|
5765
|
+
"name": "LevelIcon",
|
|
5766
|
+
"repo": "estiva-ui",
|
|
5767
|
+
"kind": "component",
|
|
5768
|
+
"importPath": "@estiva-app/ui",
|
|
5769
|
+
"sourceFile": "src/FollowSwitch.tsx",
|
|
5770
|
+
"purpose": "How a place is followed, as one 16px icon: a dashed circle for Important, a full one for All, a dashed one with a plus, muted, for Not following.",
|
|
5771
|
+
"purposeFrom": "comment",
|
|
5772
|
+
"props": [
|
|
5773
|
+
{
|
|
5774
|
+
"name": "level",
|
|
5775
|
+
"takes": "all | important",
|
|
5776
|
+
"required": true,
|
|
5777
|
+
"note": "The level it is followed at; `undefined` draws Not following."
|
|
5778
|
+
},
|
|
5779
|
+
{
|
|
5780
|
+
"name": "people",
|
|
5781
|
+
"takes": "true/false",
|
|
5782
|
+
"required": false,
|
|
5783
|
+
"note": "People rather than circles: for a place that is a group's own (Miky, 2 Nov)."
|
|
5784
|
+
}
|
|
5785
|
+
],
|
|
5786
|
+
"variants": [
|
|
5787
|
+
{
|
|
5788
|
+
"prop": "level",
|
|
5789
|
+
"values": [
|
|
5790
|
+
"all",
|
|
5791
|
+
"important"
|
|
5792
|
+
]
|
|
5793
|
+
}
|
|
5794
|
+
],
|
|
5795
|
+
"ownsBehaviours": [],
|
|
5796
|
+
"status": "stable",
|
|
5797
|
+
"migrationStage": null,
|
|
5798
|
+
"docsId": "people-followswitch--docs",
|
|
5799
|
+
"storyId": "people-followswitch--important",
|
|
5800
|
+
"docPage": null,
|
|
5801
|
+
"app": null,
|
|
5802
|
+
"looks": []
|
|
5803
|
+
},
|
|
5673
5804
|
{
|
|
5674
5805
|
"name": "Lightbox",
|
|
5675
5806
|
"repo": "estiva-ui",
|
|
@@ -6662,6 +6793,12 @@
|
|
|
6662
6793
|
"required": false,
|
|
6663
6794
|
"note": "Opens the list — usually a `MembersDialog`."
|
|
6664
6795
|
},
|
|
6796
|
+
{
|
|
6797
|
+
"name": "label",
|
|
6798
|
+
"takes": "text",
|
|
6799
|
+
"required": false,
|
|
6800
|
+
"note": "The button's accessible name, when the list it opens is not \"members\" — \"Who follows <name>: 4\"."
|
|
6801
|
+
},
|
|
6665
6802
|
{
|
|
6666
6803
|
"name": "className",
|
|
6667
6804
|
"takes": "text",
|
|
@@ -12335,6 +12472,97 @@
|
|
|
12335
12472
|
"app": null,
|
|
12336
12473
|
"looks": []
|
|
12337
12474
|
},
|
|
12475
|
+
{
|
|
12476
|
+
"name": "WhoFollowsDialog",
|
|
12477
|
+
"repo": "estiva-ui",
|
|
12478
|
+
"kind": "component",
|
|
12479
|
+
"importPath": "@estiva-app/ui",
|
|
12480
|
+
"sourceFile": "src/WhoFollowsDialog.tsx",
|
|
12481
|
+
"purpose": "Who follows a place, at All and at Important, with \"Add someone\" — the list a MembersPill opens beside a FollowSwitch.",
|
|
12482
|
+
"purposeFrom": "page",
|
|
12483
|
+
"props": [
|
|
12484
|
+
{
|
|
12485
|
+
"name": "title",
|
|
12486
|
+
"takes": "text",
|
|
12487
|
+
"required": true,
|
|
12488
|
+
"note": "The place's name: the title reads \"Who follows <title>\"."
|
|
12489
|
+
},
|
|
12490
|
+
{
|
|
12491
|
+
"name": "all",
|
|
12492
|
+
"takes": "MembersDialogMember[]",
|
|
12493
|
+
"required": true,
|
|
12494
|
+
"note": "Who follows it at All, in the order to draw them."
|
|
12495
|
+
},
|
|
12496
|
+
{
|
|
12497
|
+
"name": "important",
|
|
12498
|
+
"takes": "MembersDialogMember[]",
|
|
12499
|
+
"required": true,
|
|
12500
|
+
"note": "Who follows it at Important."
|
|
12501
|
+
},
|
|
12502
|
+
{
|
|
12503
|
+
"name": "candidates",
|
|
12504
|
+
"takes": "MembersDialogCandidate[]",
|
|
12505
|
+
"required": false,
|
|
12506
|
+
"note": "Who \"Add someone\" may offer. Everyone listed is left out by id; leave the viewer out yourself — they join with the switch, not by adding themselves."
|
|
12507
|
+
},
|
|
12508
|
+
{
|
|
12509
|
+
"name": "onAdd",
|
|
12510
|
+
"takes": "a handler",
|
|
12511
|
+
"required": false,
|
|
12512
|
+
"note": "Adds the people chosen. With it, the \"Add someone\" row shows and opens the same add layer as `MembersDialog`'s."
|
|
12513
|
+
},
|
|
12514
|
+
{
|
|
12515
|
+
"name": "initialView",
|
|
12516
|
+
"takes": "list | add",
|
|
12517
|
+
"required": false,
|
|
12518
|
+
"note": "`add` opens straight on the add layer, as a menu's \"Add someone…\" does."
|
|
12519
|
+
},
|
|
12520
|
+
{
|
|
12521
|
+
"name": "onClose",
|
|
12522
|
+
"takes": "a handler",
|
|
12523
|
+
"required": true,
|
|
12524
|
+
"note": null
|
|
12525
|
+
}
|
|
12526
|
+
],
|
|
12527
|
+
"variants": [
|
|
12528
|
+
{
|
|
12529
|
+
"prop": "initialView",
|
|
12530
|
+
"values": [
|
|
12531
|
+
"list",
|
|
12532
|
+
"add"
|
|
12533
|
+
]
|
|
12534
|
+
}
|
|
12535
|
+
],
|
|
12536
|
+
"ownsBehaviours": [
|
|
12537
|
+
{
|
|
12538
|
+
"id": "portal",
|
|
12539
|
+
"behaviour": "Floats on top of the page"
|
|
12540
|
+
},
|
|
12541
|
+
{
|
|
12542
|
+
"id": "press-outside",
|
|
12543
|
+
"behaviour": "Closes on a press outside"
|
|
12544
|
+
},
|
|
12545
|
+
{
|
|
12546
|
+
"id": "page-keys",
|
|
12547
|
+
"behaviour": "Takes its keys by itself"
|
|
12548
|
+
},
|
|
12549
|
+
{
|
|
12550
|
+
"id": "focus",
|
|
12551
|
+
"behaviour": "Holds focus inside while open, and gives it back"
|
|
12552
|
+
},
|
|
12553
|
+
{
|
|
12554
|
+
"id": "scroll-lock",
|
|
12555
|
+
"behaviour": "Stops the page behind it scrolling"
|
|
12556
|
+
}
|
|
12557
|
+
],
|
|
12558
|
+
"status": "stable",
|
|
12559
|
+
"migrationStage": null,
|
|
12560
|
+
"docsId": "people-whofollowsdialog--docs",
|
|
12561
|
+
"storyId": "people-whofollowsdialog--default",
|
|
12562
|
+
"docPage": "src/WhoFollowsDialog.mdx",
|
|
12563
|
+
"app": null,
|
|
12564
|
+
"looks": []
|
|
12565
|
+
},
|
|
12338
12566
|
{
|
|
12339
12567
|
"name": "whoReacted",
|
|
12340
12568
|
"repo": "estiva-ui",
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
|
|
2
|
+
import * as FollowSwitchStories from './FollowSwitch.stories'
|
|
3
|
+
|
|
4
|
+
<Meta of={FollowSwitchStories} />
|
|
5
|
+
|
|
6
|
+
# FollowSwitch
|
|
7
|
+
|
|
8
|
+
How you follow a place, in one button before its title: Not following,
|
|
9
|
+
Important or All, and back to a group's default when you chose against it.
|
|
10
|
+
|
|
11
|
+
<Canvas of={FollowSwitchStories.Live} />
|
|
12
|
+
|
|
13
|
+
## When
|
|
14
|
+
|
|
15
|
+
- Before a place's title, where the viewer changes how it lights for them.
|
|
16
|
+
- **LevelIcon** alone, in a list of places, where each row shows the level but
|
|
17
|
+
is not the place to change it.
|
|
18
|
+
|
|
19
|
+
## When not
|
|
20
|
+
|
|
21
|
+
- Who else follows it, and adding someone → **WhoFollowsDialog**.
|
|
22
|
+
- Being in a thing or not, with no levels → **MembersDialog**'s Join and Leave.
|
|
23
|
+
|
|
24
|
+
## How
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { FollowSwitch, LevelIcon, type FollowChoice } from '@estiva-app/ui'
|
|
28
|
+
|
|
29
|
+
const level: 'all' | 'important' | undefined = 'important'
|
|
30
|
+
|
|
31
|
+
<FollowSwitch
|
|
32
|
+
level={level}
|
|
33
|
+
label="Item one"
|
|
34
|
+
onChoose={async (choice: FollowChoice) => {}}
|
|
35
|
+
backTo={undefined}
|
|
36
|
+
/>
|
|
37
|
+
|
|
38
|
+
<LevelIcon level={level} />
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- `level` is what lights for the viewer now; `undefined` is Not following.
|
|
42
|
+
The switch is controlled: it draws the `level` it is given, so pass the new
|
|
43
|
+
one once the change is saved.
|
|
44
|
+
- `onChoose` gets `'off'`, `'important'`, `'all'`, or `'default'` from "Back to
|
|
45
|
+
Group one’s default". The button waits while its promise runs. Leave it out where
|
|
46
|
+
the level cannot change: the button then shows it and is disabled.
|
|
47
|
+
- `backTo` is the name of the group whose default the viewer chose against.
|
|
48
|
+
Leave it out when no default reaches them or they did not choose against it.
|
|
49
|
+
- `people` draws people instead of circles, for a place that is a group's own.
|
|
50
|
+
- `label` is the place's name. The button's accessible name says the level and
|
|
51
|
+
what pressing it does: "You follow it at Important: change how you follow
|
|
52
|
+
Item one".
|
|
53
|
+
|
|
54
|
+
## What it owns
|
|
55
|
+
|
|
56
|
+
| It does | So you never write | Refused when written by hand |
|
|
57
|
+
|---|---|---|
|
|
58
|
+
| Marks the level in force with a check, and Not following when there is none | a selected state per row | |
|
|
59
|
+
| Waits while `onChoose` runs, so one pick is one change | a busy flag around it | |
|
|
60
|
+
| Offers "Back to `backTo`’s default" only when `backTo` is given | a second menu section | |
|
|
61
|
+
|
|
62
|
+
## Props
|
|
63
|
+
|
|
64
|
+
<Controls of={FollowSwitchStories.Important} />
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { FollowSwitch, LevelIcon, type FollowChoice, type FollowLevel } from './FollowSwitch'
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'People/FollowSwitch',
|
|
7
|
+
component: FollowSwitch,
|
|
8
|
+
args: { level: 'important', label: 'Item one', onChoose: () => {} },
|
|
9
|
+
} satisfies Meta<typeof FollowSwitch>
|
|
10
|
+
|
|
11
|
+
export default meta
|
|
12
|
+
type Story = StoryObj<typeof meta>
|
|
13
|
+
|
|
14
|
+
/** Following at Important: a dashed circle. Open it to pick another level. */
|
|
15
|
+
export const Important: Story = {}
|
|
16
|
+
|
|
17
|
+
/** Following at All: a full circle. */
|
|
18
|
+
export const All: Story = { args: { level: 'all' } }
|
|
19
|
+
|
|
20
|
+
/** Not following: a dashed circle with a plus, muted. */
|
|
21
|
+
export const NotFollowing: Story = { args: { level: undefined } }
|
|
22
|
+
|
|
23
|
+
/** Chose against a group's default: "Back to Group one’s default" is offered under the levels. */
|
|
24
|
+
export const AgainstADefault: Story = { args: { level: 'all', backTo: 'Group one' } }
|
|
25
|
+
|
|
26
|
+
/** A group's own place: people rather than circles. */
|
|
27
|
+
export const People: Story = { args: { level: 'important', people: true } }
|
|
28
|
+
|
|
29
|
+
/** No `onChoose`: it shows the level and cannot be changed. */
|
|
30
|
+
export const ReadOnly: Story = { args: { level: undefined, onChoose: undefined } }
|
|
31
|
+
|
|
32
|
+
/** Every icon, as a list draws them: Not following, Important and All, in circles and in people. */
|
|
33
|
+
export const Icons: Story = {
|
|
34
|
+
render: () => (
|
|
35
|
+
<div className="flex flex-col gap-3 text-text-secondary">
|
|
36
|
+
{[false, true].map((people) => (
|
|
37
|
+
<div key={String(people)} className="flex items-center gap-4">
|
|
38
|
+
{([undefined, 'important', 'all'] as const).map((level) => (
|
|
39
|
+
<LevelIcon key={level ?? 'off'} level={level} people={people} />
|
|
40
|
+
))}
|
|
41
|
+
</div>
|
|
42
|
+
))}
|
|
43
|
+
</div>
|
|
44
|
+
),
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Live: pick a level and the icon follows. */
|
|
48
|
+
export const Live: Story = {
|
|
49
|
+
render: (args) => {
|
|
50
|
+
const [level, setLevel] = useState<FollowLevel | undefined>('important')
|
|
51
|
+
const choose = (choice: FollowChoice) => setLevel(choice === 'off' ? undefined : choice === 'default' ? 'important' : choice)
|
|
52
|
+
return <FollowSwitch {...args} level={level} onChoose={choose} />
|
|
53
|
+
},
|
|
54
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/** What the FollowSwitch and WhoFollowsDialog pages claim, pinned. */
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
4
|
+
import { act, cleanup, render, screen } from '@testing-library/react'
|
|
5
|
+
import userEvent from '@testing-library/user-event'
|
|
6
|
+
import { FollowSwitch } from './FollowSwitch'
|
|
7
|
+
import { MembersPill } from './MembersPill'
|
|
8
|
+
import { WhoFollowsDialog } from './WhoFollowsDialog'
|
|
9
|
+
|
|
10
|
+
afterEach(cleanup)
|
|
11
|
+
|
|
12
|
+
describe('FollowSwitch', () => {
|
|
13
|
+
it('says the level in its name, and hands back the pick', async () => {
|
|
14
|
+
const user = userEvent.setup()
|
|
15
|
+
const onChoose = vi.fn()
|
|
16
|
+
render(<FollowSwitch level="important" label="Item one" onChoose={onChoose} />)
|
|
17
|
+
await user.click(screen.getByRole('button', { name: 'You follow it at Important: change how you follow Item one' }))
|
|
18
|
+
await user.click(await screen.findByRole('menuitem', { name: /^All/ }))
|
|
19
|
+
expect(onChoose).toHaveBeenCalledWith('all')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('says Not following when there is no level, and hands back off', async () => {
|
|
23
|
+
const user = userEvent.setup()
|
|
24
|
+
const onChoose = vi.fn()
|
|
25
|
+
render(<FollowSwitch level="all" label="Item one" onChoose={onChoose} />)
|
|
26
|
+
await user.click(screen.getByRole('button', { name: /change how you follow/ }))
|
|
27
|
+
await user.click(await screen.findByRole('menuitem', { name: /^Not following/ }))
|
|
28
|
+
expect(onChoose).toHaveBeenCalledWith('off')
|
|
29
|
+
cleanup()
|
|
30
|
+
render(<FollowSwitch level={undefined} label="Item one" onChoose={onChoose} />)
|
|
31
|
+
expect(screen.getByRole('button', { name: 'Not following: change how you follow Item one' })).toBeTruthy()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('offers Back to the default only with backTo, and hands back default', async () => {
|
|
35
|
+
const user = userEvent.setup()
|
|
36
|
+
const onChoose = vi.fn()
|
|
37
|
+
const { rerender } = render(<FollowSwitch level="all" label="Item one" onChoose={onChoose} />)
|
|
38
|
+
await user.click(screen.getByRole('button', { name: /change how you follow/ }))
|
|
39
|
+
await screen.findByRole('menuitem', { name: /^All/ })
|
|
40
|
+
expect(screen.queryByRole('menuitem', { name: /Back to/ })).toBeNull()
|
|
41
|
+
await user.keyboard('{Escape}')
|
|
42
|
+
rerender(<FollowSwitch level="all" label="Item one" onChoose={onChoose} backTo="Group one" />)
|
|
43
|
+
await user.click(screen.getByRole('button', { name: /change how you follow/ }))
|
|
44
|
+
const back = await screen.findByRole('menuitem', { name: /Back to Group one’s default/ })
|
|
45
|
+
// A chosen level is public (record a-place-lists-who-chose-a-level-and-its-teams-members): never "only you see".
|
|
46
|
+
expect(back.textContent).not.toContain('only you see')
|
|
47
|
+
await user.click(back)
|
|
48
|
+
expect(onChoose).toHaveBeenCalledWith('default')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('cannot be changed without onChoose', () => {
|
|
52
|
+
render(<FollowSwitch level={undefined} label="Item one" />)
|
|
53
|
+
expect(screen.getByRole('button', { name: /Not following/ }).hasAttribute('disabled')).toBe(true)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('waits while onChoose runs, so one pick is one change', async () => {
|
|
57
|
+
const user = userEvent.setup()
|
|
58
|
+
let done = () => {}
|
|
59
|
+
const onChoose = vi.fn(() => new Promise<void>((resolve) => (done = resolve)))
|
|
60
|
+
render(<FollowSwitch level="important" label="Item one" onChoose={onChoose} />)
|
|
61
|
+
const button = screen.getByRole('button', { name: /change how you follow/ })
|
|
62
|
+
await user.click(button)
|
|
63
|
+
await user.click(await screen.findByRole('menuitem', { name: /^All/ }))
|
|
64
|
+
expect(button.hasAttribute('disabled')).toBe(true)
|
|
65
|
+
await act(async () => done())
|
|
66
|
+
expect(button.hasAttribute('disabled')).toBe(false)
|
|
67
|
+
expect(onChoose).toHaveBeenCalledTimes(1)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('stops waiting when the save fails, without throwing past it', async () => {
|
|
71
|
+
const user = userEvent.setup()
|
|
72
|
+
let fail = (_: Error) => {}
|
|
73
|
+
const onChoose = vi.fn(() => new Promise<void>((_, reject) => (fail = reject)))
|
|
74
|
+
const unhandled = vi.fn()
|
|
75
|
+
process.on('unhandledRejection', unhandled)
|
|
76
|
+
render(<FollowSwitch level="important" label="Item one" onChoose={onChoose} />)
|
|
77
|
+
const button = screen.getByRole('button', { name: /change how you follow/ })
|
|
78
|
+
await user.click(button)
|
|
79
|
+
await user.click(await screen.findByRole('menuitem', { name: /^All/ }))
|
|
80
|
+
await act(async () => fail(new Error('refused')))
|
|
81
|
+
expect(button.hasAttribute('disabled')).toBe(false)
|
|
82
|
+
await act(async () => new Promise((resolve) => setImmediate(resolve)))
|
|
83
|
+
process.off('unhandledRejection', unhandled)
|
|
84
|
+
expect(unhandled).not.toHaveBeenCalled()
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
describe('WhoFollowsDialog', () => {
|
|
89
|
+
const all = [{ id: 'ana', name: 'Ana Duarte', caption: 'Chose it' }]
|
|
90
|
+
const important = [{ id: 'ravi', name: 'Ravi Mehta', caption: 'Added by Ana Duarte' }]
|
|
91
|
+
|
|
92
|
+
it('lists All then Important with their counts, and Nobody for an empty group', async () => {
|
|
93
|
+
const { rerender } = render(<WhoFollowsDialog title="Item one" all={all} important={important} onClose={() => {}} />)
|
|
94
|
+
const dialog = await screen.findByRole('dialog', { name: 'Who follows Item one' })
|
|
95
|
+
const text = dialog.textContent!
|
|
96
|
+
expect(text.indexOf('All · 1')).toBeLessThan(text.indexOf('Ana Duarte'))
|
|
97
|
+
expect(text.indexOf('Ana Duarte')).toBeLessThan(text.indexOf('Important · 1'))
|
|
98
|
+
expect(text.indexOf('Important · 1')).toBeLessThan(text.indexOf('Ravi Mehta'))
|
|
99
|
+
expect(text).toContain('Added by Ana Duarte')
|
|
100
|
+
rerender(<WhoFollowsDialog title="Item one" all={[]} important={important} onClose={() => {}} />)
|
|
101
|
+
expect((await screen.findByRole('dialog')).textContent).toContain('All · 0Nobody')
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('offers Add someone only with onAdd, and leaves everyone listed out of the picker', async () => {
|
|
105
|
+
const user = userEvent.setup()
|
|
106
|
+
const onAdd = vi.fn()
|
|
107
|
+
const candidates = [
|
|
108
|
+
{ id: 'ana', label: 'Ana Duarte' },
|
|
109
|
+
{ id: 'jonas', label: 'Jonas Weber' },
|
|
110
|
+
]
|
|
111
|
+
const { rerender } = render(<WhoFollowsDialog title="Item one" all={all} important={important} candidates={candidates} onClose={() => {}} />)
|
|
112
|
+
await screen.findByRole('dialog')
|
|
113
|
+
expect(screen.queryByRole('button', { name: 'Add someone' })).toBeNull()
|
|
114
|
+
rerender(<WhoFollowsDialog title="Item one" all={all} important={important} candidates={candidates} onAdd={onAdd} onClose={() => {}} />)
|
|
115
|
+
await user.click(await screen.findByRole('button', { name: 'Add someone' }))
|
|
116
|
+
// Both names hold an "a": only the one not listed is offered.
|
|
117
|
+
await user.type(await screen.findByRole('combobox'), 'a')
|
|
118
|
+
const jonas = await screen.findByRole('option', { name: /Jonas Weber/ })
|
|
119
|
+
expect(screen.queryByRole('option', { name: /Ana Duarte/ })).toBeNull()
|
|
120
|
+
await user.click(jonas)
|
|
121
|
+
await user.click(screen.getByRole('button', { name: 'Invite' }))
|
|
122
|
+
expect(onAdd).toHaveBeenCalledWith([{ id: 'jonas', label: 'Jonas Weber' }])
|
|
123
|
+
expect(await screen.findByRole('dialog', { name: 'Who follows Item one' })).toBeTruthy()
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('opens on the add layer from a menu, and its back arrow returns to the list', async () => {
|
|
127
|
+
const user = userEvent.setup()
|
|
128
|
+
render(<WhoFollowsDialog title="Item one" all={all} important={important} onAdd={() => {}} initialView="add" onClose={() => {}} />)
|
|
129
|
+
await user.click(await screen.findByRole('button', { name: 'Back to who follows' }))
|
|
130
|
+
expect(await screen.findByRole('dialog', { name: 'Who follows Item one' })).toBeTruthy()
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe('MembersPill', () => {
|
|
135
|
+
it('takes its accessible name from label when given', () => {
|
|
136
|
+
render(<MembersPill members={[{ name: 'Ana Duarte' }]} count={2} label="Who follows Item one: 2" onClick={() => {}} />)
|
|
137
|
+
expect(screen.getByRole('button', { name: 'Who follows Item one: 2' })).toBeTruthy()
|
|
138
|
+
})
|
|
139
|
+
})
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { IconCheck, IconCircle, IconCircleDashed, IconCircleDashedPlus, IconUsers, IconUsersPlus } from '@tabler/icons-react'
|
|
3
|
+
import { IconButton } from './IconButton'
|
|
4
|
+
import { Menu, MenuItem, MenuSection } from './Menu'
|
|
5
|
+
|
|
6
|
+
/** A level someone follows a place at. Not following is `undefined`. */
|
|
7
|
+
export type FollowLevel = 'all' | 'important'
|
|
8
|
+
|
|
9
|
+
/** One pick on the switch: a level, Not following, or back to the default a group gives. */
|
|
10
|
+
export type FollowChoice = FollowLevel | 'off' | 'default'
|
|
11
|
+
|
|
12
|
+
const ICON = { size: 16, stroke: 1.5 } as const
|
|
13
|
+
|
|
14
|
+
/** Tabler has no filled people: IconUsers' two people, drawn solid. */
|
|
15
|
+
function IconUsersSolid() {
|
|
16
|
+
return (
|
|
17
|
+
<svg width={16} height={16} viewBox="0 0 24 24" fill="currentColor" aria-hidden>
|
|
18
|
+
<circle cx="9" cy="7" r="4" />
|
|
19
|
+
<path d="M3 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2z" />
|
|
20
|
+
<circle cx="17.5" cy="7.5" r="3" />
|
|
21
|
+
<path d="M16.6 15h0.9a3.5 3.5 0 0 1 3.5 3.5v2.5h-4.4v-2a5.6 5.6 0 0 0 -1.6 -4z" />
|
|
22
|
+
</svg>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface LevelIconProps {
|
|
27
|
+
/** The level it is followed at; `undefined` draws Not following. */
|
|
28
|
+
level: FollowLevel | undefined
|
|
29
|
+
/** People rather than circles: for a place that is a group's own (Miky, 2 Nov). */
|
|
30
|
+
people?: boolean
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* How a place is followed, as one 16px icon: a dashed circle for Important, a
|
|
35
|
+
* full one for All, a dashed one with a plus, muted, for Not following. With
|
|
36
|
+
* `people`, the same three as people: outline, solid, and a plus.
|
|
37
|
+
*/
|
|
38
|
+
export function LevelIcon({ level, people = false }: LevelIconProps) {
|
|
39
|
+
if (people) {
|
|
40
|
+
if (level === 'all') return <IconUsersSolid />
|
|
41
|
+
if (level === 'important') return <IconUsers {...ICON} aria-hidden />
|
|
42
|
+
return <IconUsersPlus {...ICON} aria-hidden className="text-text-muted" />
|
|
43
|
+
}
|
|
44
|
+
if (level === 'all') return <IconCircle {...ICON} aria-hidden />
|
|
45
|
+
if (level === 'important') return <IconCircleDashed {...ICON} aria-hidden />
|
|
46
|
+
return <IconCircleDashedPlus {...ICON} aria-hidden className="text-text-muted" />
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const WORDS: Record<FollowLevel, { label: string; description: string }> = {
|
|
50
|
+
important: { label: 'Important', description: 'New conversations, and replies in the ones you are in' },
|
|
51
|
+
all: { label: 'All', description: 'Every new conversation and every reply' },
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface FollowSwitchProps {
|
|
55
|
+
/** What lights for the viewer now: a level, or `undefined` for Not following. */
|
|
56
|
+
level: FollowLevel | undefined
|
|
57
|
+
/** The place's name, for the button's accessible name. */
|
|
58
|
+
label: string
|
|
59
|
+
/** Changes it. While its promise runs the button waits; a rejection is the caller's to report. Without it the switch shows the level and cannot change it. */
|
|
60
|
+
onChoose?: (choice: FollowChoice) => void | Promise<unknown>
|
|
61
|
+
/** Without `onChoose`: why it cannot be changed, said under the pointer ("This team is archived"). */
|
|
62
|
+
readOnlyReason?: string
|
|
63
|
+
/** People rather than circles, as `LevelIcon`'s `people`. */
|
|
64
|
+
people?: boolean
|
|
65
|
+
/** The line under Not following. */
|
|
66
|
+
offDescription?: string
|
|
67
|
+
/**
|
|
68
|
+
* The name of the group whose default reaches the viewer, when they chose
|
|
69
|
+
* against it: offers "Back to <name>’s default". Leave it out otherwise.
|
|
70
|
+
*/
|
|
71
|
+
backTo?: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The one switch on a place: Not following, Important or All, each with what
|
|
76
|
+
* it lights, and "Back to <name>’s default" when the viewer chose against a
|
|
77
|
+
* group's default. It sits before the place's title, drawn as `LevelIcon`.
|
|
78
|
+
*/
|
|
79
|
+
export function FollowSwitch({ level, label, onChoose, readOnlyReason, people = false, offDescription = 'Nothing here lights for you', backTo }: FollowSwitchProps) {
|
|
80
|
+
const [busy, setBusy] = useState(false)
|
|
81
|
+
const now = level ? `You follow it at ${WORDS[level].label}` : 'Not following'
|
|
82
|
+
const button = (
|
|
83
|
+
<IconButton aria-label={`${now}: change how you follow ${label}`} tooltip={now} disabled={!onChoose || busy} disabledReason={onChoose ? undefined : readOnlyReason}>
|
|
84
|
+
<LevelIcon level={level} people={people} />
|
|
85
|
+
</IconButton>
|
|
86
|
+
)
|
|
87
|
+
if (!onChoose) return button
|
|
88
|
+
|
|
89
|
+
const choose = async (choice: FollowChoice) => {
|
|
90
|
+
if (busy) return
|
|
91
|
+
setBusy(true)
|
|
92
|
+
try {
|
|
93
|
+
await onChoose(choice)
|
|
94
|
+
} catch {
|
|
95
|
+
// The caller says it could not save; the switch only stops waiting, and keeps drawing the `level` it is given.
|
|
96
|
+
} finally {
|
|
97
|
+
setBusy(false)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const item = (choice: 'off' | FollowLevel, text: string, description: string, leading: FollowLevel | undefined) => {
|
|
101
|
+
const on = choice === 'off' ? !level : level === choice
|
|
102
|
+
return (
|
|
103
|
+
<MenuItem
|
|
104
|
+
leading={<LevelIcon level={leading} people={people} />}
|
|
105
|
+
label={text}
|
|
106
|
+
description={description}
|
|
107
|
+
selected={on}
|
|
108
|
+
trailing={on ? <IconCheck {...ICON} aria-hidden /> : undefined}
|
|
109
|
+
onClick={() => void choose(choice)}
|
|
110
|
+
/>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
return (
|
|
114
|
+
<Menu trigger={button}>
|
|
115
|
+
<MenuSection label="How you follow it">
|
|
116
|
+
{item('off', 'Not following', offDescription, undefined)}
|
|
117
|
+
{item('important', WORDS.important.label, WORDS.important.description, 'important')}
|
|
118
|
+
{item('all', WORDS.all.label, WORDS.all.description, 'all')}
|
|
119
|
+
</MenuSection>
|
|
120
|
+
{backTo && (
|
|
121
|
+
<MenuSection label={`${backTo} gives you Important`}>
|
|
122
|
+
<MenuItem label={`Back to ${backTo}’s default`} description={level ? 'Your choice no longer applies' : 'Your choice no longer applies; only you see that you changed it'} onClick={() => void choose('default')} />
|
|
123
|
+
</MenuSection>
|
|
124
|
+
)}
|
|
125
|
+
</Menu>
|
|
126
|
+
)
|
|
127
|
+
}
|