Skip to content

Commit 37fb160

Browse files
docs: update README.md with new components and enhanced examples (#65)
- Added documentation for MudStaticRadioGroup and MudStaticRadio. - Updated MudStaticTextField example to include AdornmentToggledIcon. - Improved showPassword script example in README and source code using WeakMap for better robustness. - Enhanced "Getting Started" section with service registration and JS initialization details. - Fixed minor typos and updated the "Why" section. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Anu6is <[email protected]>
1 parent 74f7006 commit 37fb160

2 files changed

Lines changed: 69 additions & 24 deletions

File tree

README.md

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Tailored specifically for [Static Server-Side Rendered](https://learn.microsoft.
2525
> Default pword: `MudStatic123!`
2626
2727
## :thinking: Why MudBlazor.StaticInput? :thinking:
28-
- **Rapid SSSR Integration:** Effortlessly add MudBlazor components to your static SSR pages, saving development time.
28+
- **Rapid Static SSR Integration:** Effortlessly add MudBlazor components to your static SSR pages, saving development time.
2929
- **Focus on Forms:** Streamline development of forms and edit forms, for use cases such as Microsoft Identity Login forms.
3030
- **Preserved Look & Feel:** Maintains the consistent design and user experience of MudBlazor. Ensuring uniformity across all pages.
3131
- **Maintains Flexibility:** By inheriting core MudBlazor components, StaticInput maintains the same flexibility as the original components.
@@ -88,7 +88,8 @@ The set of components and features may extend over time. Currently, StaticInput
8888
<MudStaticTextField @bind-Value="@Password"
8989
InputType="InputType.Password"
9090
Adornment="Adornment.End"
91-
AdornmentIcon="@Icons.Material.Outlined.VisibilityOff"
91+
AdornmentIcon="@Icons.Material.Outlined.Visibility"
92+
AdornmentToggledIcon="@Icons.Material.Outlined.VisibilityOff"
9293
AdornmentClickFunction="showPassword" />
9394
```
9495
```cs
@@ -98,24 +99,48 @@ The set of components and features may extend over time. Currently, StaticInput
9899
```
99100
```js
100101
<script>
101-
let timeoutId;
102-
103-
function showPassword(inputElement, button) {
104-
if (inputElement.type === 'password') {
105-
inputElement.type = 'text';
106-
clearTimeout(timeoutId);
107-
timeoutId = setTimeout(function () {
108-
inputElement.type = 'password';
109-
}, 5000);
110-
} else {
111-
inputElement.type = 'password';
112-
clearTimeout(timeoutId);
113-
}
114-
}
102+
const passwordTimeouts = new WeakMap();
103+
function showPassword(inputElement) {
104+
if (!inputElement) return;
105+
106+
const existingTimeout = passwordTimeouts.get(inputElement);
107+
if (existingTimeout) clearTimeout(existingTimeout);
108+
109+
if (inputElement.type === 'password') {
110+
inputElement.type = 'text';
111+
const timeoutId = setTimeout(function () {
112+
inputElement.type = 'password';
113+
passwordTimeouts.delete(inputElement);
114+
}, 5000);
115+
passwordTimeouts.set(inputElement, timeoutId);
116+
} else {
117+
inputElement.type = 'password';
118+
passwordTimeouts.delete(inputElement);
119+
}
120+
}
115121
</script>
116122
```
117123
</details>
118124

125+
### MudStaticRadioGroup
126+
<details>
127+
<summary>
128+
Radio buttons allow the user to select one option from a set.
129+
</summary>
130+
131+
```html
132+
<MudStaticRadioGroup @bind-Value="@SelectedOption" Color="Color.Primary">
133+
<MudStaticRadio Value="@("Option 1")" Color="Color.Secondary">Option 1</MudStaticRadio>
134+
<MudStaticRadio Value="@("Option 2")">Option 2</MudStaticRadio>
135+
</MudStaticRadioGroup>
136+
```
137+
```cs
138+
@code {
139+
public string SelectedOption { get; set; } = "Option 1";
140+
}
141+
```
142+
</details>
143+
119144
### MudStaticNavDrawerToggle
120145
<details>
121146
<summary>
@@ -138,7 +163,7 @@ The set of components and features may extend over time. Currently, StaticInput
138163
### MudStaticNavGroup
139164
<details>
140165
<summary>
141-
Collapse/Expand a MudStaticNavGroup by clicking on it's title. Can you nested in a standard MudNavMenu
166+
Collapse/Expand a MudStaticNavGroup by clicking on its title. Can be nested in a standard MudNavMenu
142167
</summary>
143168

144169
```html
@@ -158,9 +183,24 @@ The set of components and features may extend over time. Currently, StaticInput
158183
</details>
159184

160185
## :rocket: Getting Started :rocket:
161-
To start using MudBlazor.StaticInput in your projects, simply install the package via NuGet Package Manager:
186+
To start using **MudBlazor.StaticInput** in your projects, simply install the package via NuGet Package Manager:
162187
```bash
163188
dotnet add package Extensions.MudBlazor.StaticInput
164189
```
165190
> [!NOTE]
166-
> Note: MudBlazor should already be setup for your application
191+
> **MudBlazor** should already be setup for your application.
192+
193+
### 1. Register Services
194+
Ensure MudBlazor services are registered in your `Program.cs`:
195+
```cs
196+
builder.Services.AddMudServices();
197+
```
198+
199+
### 2. Automatic Initialization
200+
The library utilizes a [Blazor JS initializer](https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/static-assets?view=aspnetcore-8.0#javascript-initializers) to automatically load the necessary client-side logic. No manual script tags are required for the core functionality in Blazor Web Apps.
201+
202+
### 3. Usage
203+
You can now start using the components in your Static SSR pages. For example, in an Identity login page:
204+
```html
205+
<MudStaticTextField @bind-Value="@Input.Email" Label="Email" For="() => Input.Email" />
206+
```

src/Components/MudStaticTextField.razor

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,23 @@
3333
/// -------------------------------------------------
3434
/// </code>
3535
/// <code>
36-
/// let timeoutId;
36+
/// const passwordTimeouts = new WeakMap();
37+
/// function showPassword(inputElement) {
38+
/// if (!inputElement) return;
39+
///
40+
/// const existingTimeout = passwordTimeouts.get(inputElement);
41+
/// if (existingTimeout) clearTimeout(existingTimeout);
3742
///
38-
/// function showPassword(inputElement, button) {
3943
/// if (inputElement.type === 'password') {
4044
/// inputElement.type = 'text';
41-
/// clearTimeout(timeoutId);
42-
/// timeoutId = setTimeout(function () {
45+
/// const timeoutId = setTimeout(function () {
4346
/// inputElement.type = 'password';
47+
/// passwordTimeouts.delete(inputElement);
4448
/// }, 5000);
49+
/// passwordTimeouts.set(inputElement, timeoutId);
4550
/// } else {
4651
/// inputElement.type = 'password';
47-
/// clearTimeout(timeoutId);
52+
/// passwordTimeouts.delete(inputElement);
4853
/// }
4954
/// }
5055
/// </code>

0 commit comments

Comments
 (0)