|
1 | 1 |
|
2 | | -import {sub} from "@e280/stz" |
3 | | -import {TemplateResult, attributes, html, mixin} from "@benev/slate" |
4 | | - |
| 2 | +import {html} from "lit" |
| 3 | +import {view} from "@e280/sly" |
| 4 | +import {Auth} from "../../auth.js" |
5 | 5 | import stylesCss from "./styles.css.js" |
6 | | -import {AuthElement} from "../framework.js" |
7 | | -import {Login} from "../../../trust/exports/app.js" |
8 | 6 |
|
9 | | -@mixin.css(stylesCss) |
10 | | -export class AuthButton extends AuthElement { |
11 | | - attrs = attributes(this, { |
12 | | - "src": String, |
13 | | - }) |
| 7 | +export const AuthButton = (auth: Auth) => view.component(use => { |
| 8 | + use.css(stylesCss) |
| 9 | + const attrs = use.attrs({src: String}) |
14 | 10 |
|
15 | | - on = sub<[Login | null]>() |
| 11 | + async function clickLogout() { |
| 12 | + await auth.logout() |
| 13 | + } |
16 | 14 |
|
17 | | - #clickLogout = async() => this.on.pub( |
18 | | - await this.auth.logout() |
19 | | - ) |
| 15 | + async function clickLogin() { |
| 16 | + await auth.popup(attrs.src) |
| 17 | + } |
20 | 18 |
|
21 | | - #clickLogin = async() => this.on.pub( |
22 | | - await this.auth.popup(this.attrs.src) |
| 19 | + return (auth.login |
| 20 | + |
| 21 | + ? html` |
| 22 | + <button |
| 23 | + class=logout |
| 24 | + theme-button=logout |
| 25 | + part="button button-logout" |
| 26 | + @click="${clickLogout}"> |
| 27 | + <slot name=logout>Logout</slot> |
| 28 | + </button> |
| 29 | + ` |
| 30 | + |
| 31 | + : html` |
| 32 | + <button |
| 33 | + class=login |
| 34 | + theme-button=login |
| 35 | + part="button button-login" |
| 36 | + @click="${clickLogin}"> |
| 37 | + <slot>Login</slot> |
| 38 | + </button> |
| 39 | + ` |
23 | 40 | ) |
24 | | - |
25 | | - render(): TemplateResult { |
26 | | - const {auth} = this |
27 | | - const {login} = auth |
28 | | - return login |
29 | | - |
30 | | - ? html` |
31 | | - <button |
32 | | - class=logout |
33 | | - theme-button=logout |
34 | | - part="button button-logout" |
35 | | - @click="${this.#clickLogout}"> |
36 | | - <slot name=logout>Logout</slot> |
37 | | - </button> |
38 | | - ` |
39 | | - |
40 | | - : html` |
41 | | - <button |
42 | | - class=login |
43 | | - theme-button=login |
44 | | - part="button button-login" |
45 | | - @click="${this.#clickLogin}"> |
46 | | - <slot>Login</slot> |
47 | | - </button> |
48 | | - ` |
49 | | - } |
50 | | -} |
| 41 | +}) |
51 | 42 |
|
0 commit comments