-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create generate_from_spec.py which creates almost all the boilerplate…
… for a new component based on ComponentSpec
- Loading branch information
1 parent
5e6530e
commit ffbbec2
Showing
8 changed files
with
309 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from dataclasses import dataclass | ||
from typing import Any, Callable | ||
|
||
from pydantic import validate_arguments | ||
|
||
import mesop.components.component_name.component_name_pb2 as component_name_pb | ||
from mesop.component_helpers import ( | ||
handler_type, | ||
insert_component, | ||
register_event_mapper, | ||
) | ||
from mesop.events import MesopEvent | ||
|
||
# INSERT_EVENTS | ||
|
||
|
||
@validate_arguments | ||
def component_name( | ||
*, | ||
# INSERT_COMPONENT_PARAMS | ||
): | ||
""" | ||
TODO_doc_string | ||
""" | ||
insert_component( | ||
key=key, | ||
type_name="component_name", | ||
proto=component_name_pb.ComponentNameType( | ||
# INSERT_PROTO_CALLSITE | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,34 @@ | ||
import {ChangeDetectionStrategy, Component, Input} from '@angular/core'; | ||
import {MatCheckboxChange} from '@angular/material/checkbox'; | ||
import {Component, Input} from '@angular/core'; | ||
import { | ||
Click, | ||
Key, | ||
Type, | ||
UserEvent, | ||
} from 'mesop/mesop/protos/ui_jspb_proto_pb/mesop/protos/ui_pb'; | ||
import {ComponentNameType} from 'mesop/mesop/components/component_name/component_name_jspb_proto_pb/mesop/components/component_name/component_name_pb'; | ||
import {Channel} from '../../web/src/services/channel'; | ||
|
||
@Component({ | ||
selector: 'mesop-{component-name}', | ||
templateUrl: '{component_name}.ng.html', | ||
// selector: 'mesop-{component-name}', | ||
templateUrl: 'component_name.ng.html', | ||
standalone: true, | ||
}) | ||
export class ComponentNameComponent { | ||
@Input({required: true}) type!: Type; | ||
@Input() key!: Key; | ||
private _config!: ComponentNameType; | ||
isChecked = false; | ||
value: any; | ||
|
||
constructor(private readonly channel: Channel) {} | ||
|
||
ngOnChanges() { | ||
this._config = ComponentNameType.deserializeBinary( | ||
this.type.getValue() as unknown as Uint8Array, | ||
); | ||
this.value = this._config.getDefaultValue(); | ||
} | ||
|
||
config(): ComponentNameType { | ||
return this._config; | ||
} | ||
|
||
handleCheckboxChange(event: MatCheckboxChange) { | ||
this.isChecked = event.checked; | ||
const userEvent = new UserEvent(); | ||
userEvent.setBool(event.checked); | ||
userEvent.setHandlerId(this.config().getOnUpdateHandlerId()!); | ||
userEvent.setKey(this.key); | ||
this.channel.dispatch(userEvent); | ||
} | ||
// INSERT_EVENT_METHODS: | ||
} |
Oops, something went wrong.