-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexplicit-props.stories.ts
83 lines (73 loc) · 2.12 KB
/
explicit-props.stories.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import {
customElement,
FASTElement,
observable,
html,
} from '@microsoft/fast-element';
import { html as litHtml } from 'lit';
import '../esbuild/index.js';
import {
AcsMicrophoneHandlers,
AcsMicrophoneState,
} from '../src/MicrophoneButtonContext.js';
export default {
title: 'ExplicitProps',
component: 'acs-microphone-button',
argTypes: {},
};
export const Muted = () => litHtml`
<acs-microphone-button explicitprops .state=${{checked: true}}>
</acs-microphone-button>
`
// Observation: `explicitprops` with `checked: false` breaks the UI. What ?!
// Fix: Only default slot was broken.
export const Unmuted = () => litHtml`
<acs-microphone-button explicitprops .state=${{checked: false}}>
</acs-microphone-button>
`
export const Alert = () => litHtml`
<acs-microphone-button explicitprops .state=${{checked: true}} .handlers=${{
mute: async (): Promise<void> => {
alert('mute!')
},
unmute: async (): Promise<void> => {
alert('unmute!')
},
}}>
</acs-microphone-button>
`
// Observation: Lit -> FAST template bridge loses type safety in properties.
export const LostThemTypes = () => litHtml`
<acs-microphone-button explicitprops .handlers=${{boop: true}} .state=${{checked: true}}>
</acs-microphone-button>
`
// Observation: FAST -> FAST template also loses type safety when setting properties.
const template = html`
<acs-microphone-button
explicitprops
:state=${x => x.state}
:handlers=${x => x.handlers}
>
</acs-microphone-button>
`;
@customElement({ name: 'story-microphone-wrapped', template })
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class StoryMicrophoneWrapped extends FASTElement {
@observable state: AcsMicrophoneState = {
checked: true,
};
handlers: AcsMicrophoneHandlers;
constructor() {
super();
this.handlers = {
mute: async (): Promise<void> => {
this.state = { ...this.state, checked: true };
},
unmute: async (): Promise<void> => {
this.state = { ...this.state, checked: false };
},
};
}
}
export const Wrapped = () =>
litHtml`<story-microphone-wrapped></story-microphone-wrapped>`;