Skip to content

Commit 8d31814

Browse files
committed
Revert "Support @type=multi toggle"
This reverts commit c760838.
1 parent c760838 commit 8d31814

File tree

12 files changed

+1287
-534
lines changed

12 files changed

+1287
-534
lines changed

docs-app/app/app.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'decorator-transforms/globals';
21
import './css/styles.css';
32

43
import Application from '@ember/application';

docs-app/ember-cli-build.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ module.exports = function (defaults) {
88
// Add options here
99
'ember-cli-babel': {
1010
enableTypeScriptTransform: true,
11-
disableDecoratorTransforms: true,
12-
},
13-
babel: {
14-
plugins: [
15-
// add the new transform.
16-
require.resolve('decorator-transforms'),
17-
],
1811
},
1912
});
2013

@@ -50,7 +43,7 @@ module.exports = function (defaults) {
5043
// staticEmberSource: true,
5144
packagerOptions: {
5245
webpackConfig: {
53-
devtool: 'source-map',
46+
devtool: process.env.CI ? 'source-map' : 'eval',
5447
resolve: {
5548
alias: {
5649
path: 'path-browserify',

docs-app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
},
2929
"dependencies": {
3030
"assert": "^2.0.0",
31-
"decorator-transforms": "^1.1.0",
3231
"docs-api": "workspace:*",
3332
"ember-focus-trap": "^1.1.0",
3433
"ember-headless-form": "^1.0.0",

docs-app/public/docs/3-ui/toggle-group.md

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,10 @@ import { ToggleGroup } from 'ember-primitives';
2121
<AlignRight />
2222
</t.Item>
2323
</ToggleGroup>
24-
25-
<ToggleGroup @type="multi" class="toggle-group" as |t|>
26-
<t.Item @value="bold" aria-label="Bold text">
27-
B
28-
</t.Item>
29-
<t.Item @value="italic" aria-label="Italicize text">
30-
I
31-
</t.Item>
32-
<t.Item @value="underline" aria-label="Underline text">
33-
U
34-
</t.Item>
35-
</ToggleGroup>
3624
</div>
3725
3826
<style>
39-
button[aria-label="Bold text"] { font-weight: bold; }
40-
button[aria-label="Italicize text"] { font-style: italic; }
41-
button[aria-label="Underline text"] { text-decoration: underline; }
42-
43-
.demo {
44-
display: flex;
45-
justify-content: center;
46-
align-items: center;
47-
gap: 1rem;
48-
}
49-
27+
.demo { display: flex; justify-content: center; align-items: center;}
5028
.toggle-group {
5129
display: inline-flex;
5230
background-color: #fff;
@@ -56,7 +34,7 @@ import { ToggleGroup } from 'ember-primitives';
5634
5735
.toggle-group > button {
5836
background-color: white;
59-
color: #black;
37+
color: #fff;
6038
height: 35px;
6139
width: 35px;
6240
display: flex;
@@ -139,30 +117,19 @@ import { ToggleGroup } from 'ember-primitives';
139117
</template>
140118
```
141119

142-
## API Reference: `@type='single'` (default)
143-
144-
```gjs live no-shadow
145-
import { ComponentSignature } from 'docs-app/docs-support';
146-
147-
<template>
148-
<ComponentSignature @module="components/toggle-group" @name="SingleSignature" />
149-
</template>
150-
```
151-
152-
## API Reference: `@type='multi'`
120+
## API Reference
153121

154122
```gjs live no-shadow
155123
import { ComponentSignature } from 'docs-app/docs-support';
156124
157125
<template>
158-
<ComponentSignature @module="components/toggle-group" @name="MultiSignature" />
126+
<ComponentSignature @module="components/toggle-group" @name="ToggleGroup" />
159127
</template>
160128
```
161129

162-
163130
<hr>
164131

165-
## API Reference: `Item`
132+
### Item
166133

167134
```gjs live no-shadow
168135
import { ComponentSignature } from 'docs-app/docs-support';

ember-primitives/.eslintrc.cjs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,5 @@ module.exports = {
1919
plugins: ['ember'],
2020
parser: 'ember-eslint-parser',
2121
},
22-
23-
{
24-
files: ['./src/components/toggle-group.gts'],
25-
rules: {
26-
'@typescript-eslint/no-explicit-any': 'off',
27-
},
28-
},
2922
],
3023
};

ember-primitives/.template-lintrc.cjs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,4 @@ module.exports = {
55
rules: {
66
'no-forbidden-elements': 'off',
77
},
8-
overrides: [
9-
{
10-
files: ['src/components/toggle-group.gts'],
11-
rules: {
12-
// https://github.com/typed-ember/glint/issues/715
13-
'no-args-paths': 'off',
14-
},
15-
},
16-
],
178
};

ember-primitives/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"ember-velcro": "^2.1.3",
4545
"reactiveweb": "^1.2.0",
4646
"tabster": "^7.0.1",
47-
"tracked-built-ins": "^3.2.0",
4847
"tracked-toolbox": "^2.0.0"
4948
},
5049
"devDependencies": {

ember-primitives/src/components/-private/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
*/
55
export function toggleWithFallback(
66
uncontrolledToggle: (...args: unknown[]) => void,
7-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8-
controlledToggle?: (...args: any[]) => void,
7+
controlledToggle?: (...args: unknown[]) => void,
98
...args: unknown[]
109
) {
1110
if (controlledToggle) {
Lines changed: 6 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import Component from '@glimmer/component';
2-
import { cached } from '@glimmer/tracking';
32
import { hash } from '@ember/helper';
43

54
import { Types } from 'tabster';
6-
import { TrackedSet } from 'tracked-built-ins';
75
// The consumer will need to provide types for tracked-toolbox.
86
// Or.. better yet, we PR to trakcked-toolbox to provide them
97
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -21,6 +19,7 @@ const TABSTER_CONFIG = JSON.stringify({
2119
},
2220
});
2321

22+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2423
export interface ItemSignature<Value = any> {
2524
/**
2625
* The button element will have aria-pressed="true" on it when the button is in the pressed state.
@@ -46,9 +45,11 @@ export interface ItemSignature<Value = any> {
4645
};
4746
}
4847

48+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4949
export type Item<Value = any> = ComponentLike<ItemSignature<Value>>;
5050

51-
export interface SingleSignature<Value> {
51+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
52+
export class ToggleGroup<Value = any> extends Component<{
5253
Element: HTMLDivElement;
5354
Args: {
5455
/**
@@ -63,136 +64,16 @@ export interface SingleSignature<Value> {
6364
*
6465
* When none of the toggles are selected, undefined will be passed.
6566
*/
66-
onChange?: (value: Value | undefined) => void;
67+
onChange: (value: Value | undefined) => void;
6768
};
6869
Blocks: {
6970
default: [
7071
{
71-
/**
72-
* The Toggle Switch
73-
*/
7472
Item: Item;
7573
},
7674
];
7775
};
78-
}
79-
80-
export interface MultiSignature<Value = any> {
81-
Element: HTMLDivElement;
82-
Args: {
83-
/**
84-
* Optionally set the initial toggle state
85-
*/
86-
value?: Value[] | Set<Value> | Value;
87-
/**
88-
* Callback for when the toggle-group's state is changed.
89-
*
90-
* Can be used to control the state of the component.
91-
*
92-
*
93-
* When none of the toggles are selected, undefined will be passed.
94-
*/
95-
onChange?: (value: Set<Value>) => void;
96-
};
97-
Blocks: {
98-
default: [
99-
{
100-
/**
101-
* The Toggle Switch
102-
*/
103-
Item: Item;
104-
},
105-
];
106-
};
107-
}
108-
109-
interface PrivateSingleSignature<Value = any> {
110-
Element: HTMLDivElement;
111-
Args: {
112-
type?: 'single';
113-
114-
/**
115-
* Optionally set the initial toggle state
116-
*/
117-
value?: Value;
118-
/**
119-
* Callback for when the toggle-group's state is changed.
120-
*
121-
* Can be used to control the state of the component.
122-
*
123-
*
124-
* When none of the toggles are selected, undefined will be passed.
125-
*/
126-
onChange?: (value: Value | undefined) => void;
127-
};
128-
Blocks: {
129-
default: [
130-
{
131-
Item: Item;
132-
},
133-
];
134-
};
135-
}
136-
137-
interface PrivateMultiSignature<Value = any> {
138-
Element: HTMLDivElement;
139-
Args: {
140-
type: 'multi';
141-
/**
142-
* Optionally set the initial toggle state
143-
*/
144-
value?: Value[] | Set<Value> | Value;
145-
/**
146-
* Callback for when the toggle-group's state is changed.
147-
*
148-
* Can be used to control the state of the component.
149-
*
150-
*
151-
* When none of the toggles are selected, undefined will be passed.
152-
*/
153-
onChange?: (value: Set<Value>) => void;
154-
};
155-
Blocks: {
156-
default: [
157-
{
158-
Item: Item;
159-
},
160-
];
161-
};
162-
}
163-
164-
function isMulti(x: 'single' | 'multi' | undefined): x is 'multi' {
165-
return x === 'multi';
166-
}
167-
168-
export class ToggleGroup<Value = any> extends Component<
169-
PrivateSingleSignature<Value> | PrivateMultiSignature<Value>
170-
> {
171-
// See: https://github.com/typed-ember/glint/issues/715
172-
<template>
173-
{{#if (isMulti this.args.type)}}
174-
<MultiToggleGroup
175-
@value={{this.args.value}}
176-
@onChange={{this.args.onChange}}
177-
...attributes
178-
as |x|
179-
>
180-
{{yield x}}
181-
</MultiToggleGroup>
182-
{{else}}
183-
<SingleToggleGroup
184-
@value={{this.args.value}}
185-
@onChange={{this.args.onChange}}
186-
...attributes
187-
as |x|
188-
>
189-
{{yield x}}
190-
</SingleToggleGroup>
191-
{{/if}}
192-
</template>
193-
}
194-
195-
class SingleToggleGroup<Value = any> extends Component<SingleSignature<Value>> {
76+
}> {
19677
@localCopy('args.value') activePressed?: Value;
19778

19879
handleToggle = (value: Value) => {
@@ -215,47 +96,3 @@ class SingleToggleGroup<Value = any> extends Component<SingleSignature<Value>> {
21596
</div>
21697
</template>
21798
}
218-
219-
class MultiToggleGroup<Value = any> extends Component<MultiSignature<Value>> {
220-
/**
221-
* Normalizes @value to a Set
222-
* and makes sure that even if the input Set is reactive,
223-
* we don't mistakenly dirty it.
224-
*/
225-
@cached
226-
get activePressed(): TrackedSet<Value> {
227-
let value = this.args.value;
228-
229-
if (!value) {
230-
return new TrackedSet();
231-
}
232-
233-
if (Array.isArray(value)) {
234-
return new TrackedSet(value);
235-
}
236-
237-
if (value instanceof Set) {
238-
return new TrackedSet(value);
239-
}
240-
241-
return new TrackedSet([value]);
242-
}
243-
244-
handleToggle = (value: Value) => {
245-
if (this.activePressed.has(value)) {
246-
this.activePressed.delete(value);
247-
} else {
248-
this.activePressed.add(value);
249-
}
250-
251-
this.args.onChange?.(new Set<Value>(this.activePressed.values()));
252-
};
253-
254-
isPressed = (value: Value) => this.activePressed.has(value);
255-
256-
<template>
257-
<div data-tabster={{TABSTER_CONFIG}} ...attributes>
258-
{{yield (hash Item=(component Toggle onChange=this.handleToggle isPressed=this.isPressed))}}
259-
</div>
260-
</template>
261-
}

ember-primitives/src/components/toggle.gts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// import Component from '@glimmer/component';
21
import { fn } from '@ember/helper';
32
import { on } from '@ember/modifier';
43

@@ -29,7 +28,7 @@ export interface Signature<Value = any> {
2928
* This can be useful when using the same function for the `@onChange`
3029
* handler with multiple `<Toggle>` components.
3130
*/
32-
onChange?: (value: Value | undefined, pressed: boolean) => void;
31+
onChange?: (value?: Value | undefined) => void;
3332

3433
/**
3534
* When used in a group of Toggles, this option will be helpful to

0 commit comments

Comments
 (0)