diff --git a/Components/EventArgs.cs b/Components/EventArgs.cs index e741dd0..6b5c968 100644 --- a/Components/EventArgs.cs +++ b/Components/EventArgs.cs @@ -7,6 +7,23 @@ public class TagRemovingEventArgs : EventArgs public bool Cancel { get; set; } = false; } + public class LightboxShowingEventArgs : EventArgs + { + public bool Cancel { get; set; } = false; + } + + public class LightboxHidingEventArgs : EventArgs + { + public bool Cancel { get; set; } = false; + } + + public class LightboxItemChangeEventArgs : EventArgs + { + public int Index { get; set; } + public int PreviousIndex { get; set; } + + } + public class InputTagCreatingEventArgs : EventArgs { public string Tag { get; set; } = string.Empty; @@ -96,4 +113,12 @@ public class VideoMetadata public string[]? Tracks { get; set; } } + public class RichTextEditorSuggestionError + { + public string ErrorMessage { get; set; } = string.Empty; + public string Trigger { get; set; } = string.Empty; + public string Query { get; set; } = string.Empty; + } + + } diff --git a/Components/RichTextEditorOptions.cs b/Components/RichTextEditorOptions.cs new file mode 100644 index 0000000..501d2eb --- /dev/null +++ b/Components/RichTextEditorOptions.cs @@ -0,0 +1,209 @@ +namespace WebAwesomeBlazor.Components +{ + + public class RichTextEditorOptions + { + /// + /// Features available in the editor. To remove from the editor entirely set their corresponding properties to false: their tools, shortcuts, and input rules are left out, and they're stripped from the value and from pasted content. Use lists to remove both list types. + /// + public RichTextEditorFeatures DisabledFeatures { get; set; } = new(); + + /// + /// The format of the editor's value; Default is HTML. If UseMarkdown is true, the format will be Markdown. + /// + public bool UseMarkdown { get; set; } = false; + /// + /// The heading levels users can apply. Other headings are converted to the nearest allowed level. Set all to false to remove headings. + /// + public RichTextEditorHeadingLevels HeadingLevels { get; set; } = + [ + RichTextEditorHeadingLevel.H1, + RichTextEditorHeadingLevel.H2, + RichTextEditorHeadingLevel.H3, + ]; + + /// + /// The highlight colors offered in the color menu + /// + public RichTextEditorColorOptions? HighlightColors { get; set; } + /// + /// The icon library used for the toolbar and popover icons. Defaults to system. Set it to default (or any registered library) to draw the icons from that library instead, e.g. to use Font Awesome Pro icons with a kit code. + /// + public string IconLibrary { get; set; } = "system"; + + /// + /// The rel given to links created in the editor. Overrides the default rel that _blank adds. + /// + public string LinkRel { get; set; } = string.Empty; + + + /// + /// The target given to links created in the editor. _blank also sets rel="noopener noreferrer". + /// + public string LinkTarget { get; set; } = string.Empty; + /// + /// The maximum number of characters of text, not counting markup, that will be considered valid. Typing beyond it isn't blocked; the editor becomes invalid + /// + public int? MaxLength { get; set; } + /// + /// The minimum number of characters of text, not counting markup, that will be considered valid. + /// + public int? MinLength { get; set; } + + + /// + /// The text colors offered in the color menu + /// + public RichTextEditorColorOptions? TextColors { get; set; } + + /// + /// The tools to show in the toolbar. Add items to the list to show them in the toolbar. + /// + public RichTextEditorToolbarOptions Toolbar { get; set; } = []; + /// + /// Where the toolbar sits. + /// + public RichTextEditorToolbarPlacement ToolbarPlacement { get; set; } = RichTextEditorToolbarPlacement.Top; + + /// + /// Set to false to turn off linking URLs as they're typed. + /// + public bool AutoLink { get; set; } = true; + + /// + /// Shows a character count below the editor. When maxlength is set, shows remaining characters instead. + /// + public bool ShowCount { get; set; } = false; + + /// + /// Turns off the Markdown-style shortcuts that format content as users type, such as # for a heading, - for a list, and ==text== for a highlight. Keyboard shortcuts still work. + /// + public bool DisableMarkdownShortcuts { get; set; } = false; + /// + /// Turns off smart quotes and the replacement of ... and -- with an ellipsis and an em dash as users type. + /// + public bool DisableSmartPunctuation { get; set; } = false; + + } + + public sealed class EditorColor + { + public string Color { get; set; } = string.Empty; + public string Label { get; set; } = string.Empty; + public EditorColor(string color, string label) + { + Color = color; + Label = label; + } + } + + public sealed class RichTextEditorHeadingLevels : List + { + public override string ToString() + { + return string.Join(" ", + this.Select(x => x.GetDescription())); + } + } + + public sealed class RichTextEditorToolbarOptions : List + { + public override string ToString() + { + return string.Join(" ", + this.Select(x => x.GetDescription())); + } + } + + public sealed class RichTextEditorFeatures : List + { + public override string ToString() + { + return string.Join(" ", + this.Select(x => x.GetDescription())); + } + } + + + public sealed class RichTextEditorColorOptions + { + private readonly string? _stringValue; + private readonly string[]? _stringArrayValue; + private readonly List? _editorColors; + + private RichTextEditorColorOptions( + string? stringValue = null, + string[]? stringArrayValue = null, + List? editorColors = null) + { + _stringValue = stringValue; + _stringArrayValue = stringArrayValue; + _editorColors = editorColors; + } + + public static implicit operator RichTextEditorColorOptions(string value) + { + return new(stringValue: value); + } + + public static implicit operator RichTextEditorColorOptions(string[] value) + { + return new(stringArrayValue: value); + } + + public static implicit operator RichTextEditorColorOptions(List value) + { + return new(editorColors: value); + } + + public override string ToString() + { + if (_stringValue is not null) + return _stringValue; + + return string.Empty; + } + + public object GetValue() + { + if (_stringValue is not null) return _stringValue; + if (_stringArrayValue is not null) return _stringArrayValue; + if (_editorColors is not null) return _editorColors; + + return string.Empty; + } + } + + + public sealed class RichTextEditorSuggestion + { + + private readonly Func>>? _itemsFunc; + + public string Trigger { get; } + + public RichTextEditorSuggestion( + string trigger, + Func>> function) + { + Trigger = trigger; + _itemsFunc = function; + } + + public async Task> InvokeAsync(string query) + { + + if (_itemsFunc is not null) return await _itemsFunc.Invoke(query); + + return default!; + } + + + } + public sealed class RichTextEditorSuggestionItem + { + public string? Value { get; set; } + public string Label { get; set; } = string.Empty; + public string? Description { get; set; } + } +} diff --git a/Components/WACodeHighlighter.razor b/Components/WACodeHighlighter.razor new file mode 100644 index 0000000..6dfebf8 --- /dev/null +++ b/Components/WACodeHighlighter.razor @@ -0,0 +1,16 @@ +@using System.Globalization +@inherits WAComponentBase + + @ChildContent + \ No newline at end of file diff --git a/Components/WACodeHighlighter.razor.cs b/Components/WACodeHighlighter.razor.cs new file mode 100644 index 0000000..551d0fe --- /dev/null +++ b/Components/WACodeHighlighter.razor.cs @@ -0,0 +1,121 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; + +namespace WebAwesomeBlazor.Components +{ + public partial class WACodeHighlighter : WAComponentBase + { + #region Parameters + /// + /// The code to display. It takes precedence over ChildContent and renders verbatim, without dedenting. Use it when the code is dynamic or when escaping ChildContent is impractical. + /// + [Parameter] + public string? Code { get; set; } + + /// + /// An accessible label for the code region. When omitted, a localized "Code" label is used. + /// + [Parameter] + public string? Label { get; set; } + + /// + /// The language of the code, e.g. html, css, js, or python. Common languages are bundled and the rest load on demand. Leave it empty to display plain text. + /// + [Parameter] + public string? CodeLanguage { get; set; } + + /// + /// Shows the copy button. + /// + [Parameter] + public bool ShowCopyButton { get; set; } = true; + + /// + /// Code is dedented by default. Disable to preserve ChildContent code exactly as written instead of dedenting + /// + [Parameter] + public bool Dedent { get; set; } = true; + + /// + /// Wraps long lines instead of scrolling horizontally. + /// + [Parameter] + public bool Wrap { get; set; } = false; + + /// + /// Emitted when no grammar exists for the current language. The code renders as plain text. + /// + [Parameter] + public EventCallback GrammarError { get; set; } + + /// + /// Emitted when the grammar for the current language has loaded and the code has been highlighted. + /// + [Parameter] + public EventCallback Loaded { get; set; } + + #endregion + + #region Lifecycle + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await base.OnAfterRenderAsync(firstRender); + if (firstRender) + { + + _instance = await SafeInvokeAsync("initialize", Element, objRef); + } + } + + protected override async ValueTask DisposeAsyncCore(bool disposing) + { + if (disposing) + { + try + { + if (_instance is not null) + await _instance.InvokeVoidAsync("dispose"); + + } + catch (JSDisconnectedException) + { + } + objRef?.Dispose(); + + } + + } + protected override async Task OnInitializedAsync() + { + objRef ??= DotNetObjectReference.Create(this); + + + AdditionalAttributes ??= new Dictionary(); + + await base.OnInitializedAsync(); + } + #endregion + + #region State + private DotNetObjectReference objRef = default!; + #endregion + + #region Event Handlers + [JSInvokable] + public async Task HandleGrammarError() + { + await GrammarError.InvokeAsync(); + } + + [JSInvokable] + public async Task HandleLoaded() + { + await Loaded.InvokeAsync(); + } + + #endregion + + } + + +} diff --git a/Components/WACodeHighlighter.razor.js b/Components/WACodeHighlighter.razor.js new file mode 100644 index 0000000..567e790 --- /dev/null +++ b/Components/WACodeHighlighter.razor.js @@ -0,0 +1,26 @@ +// JavaScript for WACodeHighlighter component +export function initialize(element, dotnetHelper) { + if (!element) return null; + + + // Capture handler so it can be removed later + const onGrammarError = () => { + dotnetHelper.invokeMethodAsync('HandleGrammarError'); + }; + + const onLoad = () => { + dotnetHelper.invokeMethodAsync('HandleLoaded'); + }; + + // Register listener + element.addEventListener('wa-error', onGrammarError); + element.addEventListener('wa-load', onLoad); + + // Return cleanup object + return { + dispose: () => { + element.removeEventListener('wa-error', onGrammarError); + element.removeEventListener('wa-load', onLoad); + } + }; +} \ No newline at end of file diff --git a/Components/WACounter.razor b/Components/WACounter.razor new file mode 100644 index 0000000..06117cd --- /dev/null +++ b/Components/WACounter.razor @@ -0,0 +1,49 @@ +@using System.Globalization +@inherits WAComponentBase + +@if(DaysContent is not null) + { + @DaysContent + } + @if (SecondsContent is not null) + { + @SecondsContent + } + @if (MinutesContent is not null) + { + @MinutesContent + } + @if (HoursContent is not null) + { + @HoursContent + } + @if (MonthsContent is not null) + { + @MonthsContent + } + @if (YearsContent is not null) + { + @YearsContent + } + @if (FinishedContent is not null) + { + @FinishedContent + } + \ No newline at end of file diff --git a/Components/WACounter.razor.cs b/Components/WACounter.razor.cs new file mode 100644 index 0000000..1ef17a6 --- /dev/null +++ b/Components/WACounter.razor.cs @@ -0,0 +1,196 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System.Globalization; + +namespace WebAwesomeBlazor.Components +{ + public partial class WACounter : WAComponentBase + { + #region Parameters + /// + /// The date from which to calculate time from. If not set, the current date and time will be used. Setting a date/time inline may result in restting the countdown on render. + /// + [Parameter] + public DateTime? DateTimeValue { get; set; } + + /// + /// Text to show between units, such as :. + /// + [Parameter] + public string? Delimiter { get; set; } = string.Empty; + + /// + /// The direction to count. Use down to count down to the date and up to count up from it. + /// + [Parameter] + public CounterDirection Direction { get; set; } = CounterDirection.Down; + + /// + /// The number of milliseconds to count down from, starting when the counter is added to the page. Changing it starts the countdown over. Ignored when date is set or direction is up. + /// + [Parameter] + public int? Duration { get; set; } + + /// + /// The formatting style of the unit labels. + /// + [Parameter] + public CounterFormat Format { get; set; } = CounterFormat.Long; + + /// + /// A label that describes the counter to assistive devices. + /// + [Parameter] + public string? Label { get; set; } + + /// + /// The largest unit to show. Time beyond it rolls up into it, so two days show as 48 hours when this is hours. Units at zero ahead of the first non-zero unit are hidden unless ShowLabels is false. Falls back to the default range when either unit is invalid or the smallest unit is larger than the largest. + /// + [Parameter] + public CounterUnit LargestUnit { get; set; } = CounterUnit.Days; + + /// + /// Pauses the counter. Used PauseAsync and UnpauseAsync to change state. + /// + [Parameter] + public bool Paused { get; set; } = false; + /// + /// The smallest unit to show. Time below it is dropped. Falls back to the default range when either unit is invalid or the smallest unit is larger than the largest. + /// + [Parameter] + public CounterUnit SmallestUnit { get; set; } = CounterUnit.Seconds; + + /// + /// Shows the unit labels. + /// + [Parameter] + public bool ShowLabels { get; set; } = true; + + /// + /// A custom label for days. + /// + [Parameter] + public RenderFragment? DaysContent { get; set; } + /// + /// A custom label for minutes. + /// + [Parameter] + public RenderFragment? MinutesContent { get; set; } + /// + /// A custom label for hours. + /// + [Parameter] + public RenderFragment? HoursContent { get; set; } + /// + /// A custom label for seconds. + /// + [Parameter] + public RenderFragment? SecondsContent { get; set; } + /// + /// A custom label for months. + /// + [Parameter] + public RenderFragment? MonthsContent { get; set; } + /// + /// A custom label for years. + /// + [Parameter] + public RenderFragment? YearsContent { get; set; } + /// + /// Content to show in place of the units when a countdown is at zero, including one whose date had already passed. + /// + [Parameter] + public RenderFragment? FinishedContent { get; set; } + /// + /// Emitted when a running countdown reaches zero. Not emitted when the date had already passed. + /// + [Parameter] + public EventCallback Finished { get; set; } + + #endregion + + #region Computed Properties + string DateTimeISOString + { + get + { + if (DateTimeValue is null) return string.Empty; + return DateTimeValue.Value.ToString("o", CultureInfo.InvariantCulture); + } + } + + #endregion + #region Lifecycle + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await base.OnAfterRenderAsync(firstRender); + if (firstRender) + { + + _instance = await SafeInvokeAsync("initialize", Element, objRef); + } + } + + protected override async ValueTask DisposeAsyncCore(bool disposing) + { + if (disposing) + { + try + { + if (_instance is not null) + await _instance.InvokeVoidAsync("dispose"); + + } + catch (JSDisconnectedException) + { + } + objRef?.Dispose(); + + } + + } + protected override async Task OnInitializedAsync() + { + objRef ??= DotNetObjectReference.Create(this); + + + AdditionalAttributes ??= new Dictionary(); + + await base.OnInitializedAsync(); + } + #endregion + + #region State + private DotNetObjectReference objRef = default!; + #endregion + + #region Event Handlers + [JSInvokable] + public async Task HandleCounterFinished() + { + await Finished.InvokeAsync(); + } + #endregion + + #region Public Methods + /// + /// Pauses the counter + /// + public async Task PauseAsync() + { + Paused = true; + } + + /// + /// Resumes the counter + /// + public async Task UnpauseAsync() + { + Paused = false; + } + #endregion + + } + + +} diff --git a/Components/WACounter.razor.js b/Components/WACounter.razor.js new file mode 100644 index 0000000..49f47da --- /dev/null +++ b/Components/WACounter.razor.js @@ -0,0 +1,22 @@ +// JavaScript for WACounter component +// JavaScript for WACodeHighlighter component +export function initialize(element, dotnetHelper) { + if (!element) return null; + + + // Capture handler so it can be removed later + const onFinished = () => { + dotnetHelper.invokeMethodAsync('HandleCounterFinished'); + }; + + + // Register listener + element.addEventListener('wa-finish', onFinished); + + // Return cleanup object + return { + dispose: () => { + element.removeEventListener('wa-finish', onFinished); + } + }; +} \ No newline at end of file diff --git a/Components/WADateInput.razor.cs b/Components/WADateInput.razor.cs index 7912529..b1db7bd 100644 --- a/Components/WADateInput.razor.cs +++ b/Components/WADateInput.razor.cs @@ -225,41 +225,41 @@ public partial class WADateInput : WAComponentBase public DatePickerWeekdayFormat WeekdayFormat { get; set; } = DatePickerWeekdayFormat.Short; + /// + /// Triggered when the input is focused. + /// + [Parameter] + public EventCallback Focused { get; set; } + /// + /// Triggered when the input is blurred. + /// + [Parameter] + public EventCallback Blurred { get; set; } + + #endregion #region Computed Properties - string AppearanceString + string AppearanceString => Appearance switch { - get - { - return Appearance switch - { - InputAppearance.Filled => "filled", - InputAppearance.Outlined => "outlined", - InputAppearance.FilledOutlined => "filled-outlined", - _ => "outlined" - //Only filled and outlined are valid for inputs - }; - } - } - - string SizeString + InputAppearance.Filled => "filled", + InputAppearance.Outlined => "outlined", + InputAppearance.FilledOutlined => "filled-outlined", + _ => "outlined" + //Only filled and outlined are valid for inputs + }; + + string SizeString => Size switch { - get - { - return Size switch - { - InputSize.XSmall => "xs", - InputSize.Small => "s", - InputSize.Medium => "m", - InputSize.Large => "l", - InputSize.XLarge => "xl", - InputSize.Inherit => "inherit", - _ => "m" - }; - } - } + InputSize.XSmall => "xs", + InputSize.Small => "s", + InputSize.Medium => "m", + InputSize.Large => "l", + InputSize.XLarge => "xl", + InputSize.Inherit => "inherit", + _ => "m" + }; string DisabledDatesString { @@ -292,73 +292,49 @@ string DisabledDaysOfTheWeekString } } - string FirstDayOfTheWeekString + string FirstDayOfTheWeekString => FirstDayOfWeek switch { - get - { - return FirstDayOfWeek switch - { - DatePickerDayOfTheWeek.Sunday => "sun", - DatePickerDayOfTheWeek.Monday => "mon", - DatePickerDayOfTheWeek.Tuesday => "tue", - DatePickerDayOfTheWeek.Wednesday => "wed", - DatePickerDayOfTheWeek.Thursday => "thu", - DatePickerDayOfTheWeek.Friday => "fri", - DatePickerDayOfTheWeek.Saturday => "sat", - _ => "auto" - }; - } - } - - string SelectionModeString + DatePickerDayOfTheWeek.Sunday => "sun", + DatePickerDayOfTheWeek.Monday => "mon", + DatePickerDayOfTheWeek.Tuesday => "tue", + DatePickerDayOfTheWeek.Wednesday => "wed", + DatePickerDayOfTheWeek.Thursday => "thu", + DatePickerDayOfTheWeek.Friday => "fri", + DatePickerDayOfTheWeek.Saturday => "sat", + _ => "auto" + }; + + string SelectionModeString => SelectionMode switch { - get - { - return SelectionMode switch - { - DatePickerSelectionMode.Single => "single", - DatePickerSelectionMode.Range => "range", - _ => "single" - }; - } - } + DatePickerSelectionMode.Single => "single", + DatePickerSelectionMode.Range => "range", + _ => "single" + }; - string PopupPlacementString + string PopupPlacementString => PopupPlacement switch { - get - { - return PopupPlacement switch - { - DateInputPlacement.BottomStart => "bottom-start", - DateInputPlacement.BottomEnd => "bottom-end", - DateInputPlacement.TopStart => "top-start", - DateInputPlacement.TopEnd => "top-end", - DateInputPlacement.Top => "top", - DateInputPlacement.Bottom => "bottom", - DateInputPlacement.Right => "right", - DateInputPlacement.RightStart => "right-start", - DateInputPlacement.RightEnd => "right-end", - DateInputPlacement.Left => "left", - DateInputPlacement.LeftStart => "left-start", - DateInputPlacement.LeftEnd => "left-end", - _ => "bottom-start" - }; - } - } - - string WeekdayFormatString + DateInputPlacement.BottomStart => "bottom-start", + DateInputPlacement.BottomEnd => "bottom-end", + DateInputPlacement.TopStart => "top-start", + DateInputPlacement.TopEnd => "top-end", + DateInputPlacement.Top => "top", + DateInputPlacement.Bottom => "bottom", + DateInputPlacement.Right => "right", + DateInputPlacement.RightStart => "right-start", + DateInputPlacement.RightEnd => "right-end", + DateInputPlacement.Left => "left", + DateInputPlacement.LeftStart => "left-start", + DateInputPlacement.LeftEnd => "left-end", + _ => "bottom-start" + }; + + string WeekdayFormatString => WeekdayFormat switch { - get - { - return WeekdayFormat switch - { - DatePickerWeekdayFormat.Narrow => "narrow", - DatePickerWeekdayFormat.Short => "short", - DatePickerWeekdayFormat.Long => "long", - _ => "short" - }; - } - } + DatePickerWeekdayFormat.Narrow => "narrow", + DatePickerWeekdayFormat.Short => "short", + DatePickerWeekdayFormat.Long => "long", + _ => "short" + }; #endregion @@ -497,6 +473,19 @@ public async Task HandleInputChange(string value) } } } + + [JSInvokable] + public async Task HandleInputFocus() + { + await Focused.InvokeAsync(); + } + + [JSInvokable] + public async Task HandleInputBlur() + { + await Blurred.InvokeAsync(); + } + private async Task OnValueChanged(ChangeEventArgs e) { var oldValue = Value; @@ -673,7 +662,10 @@ public async Task SetFocusAsync() await SafeInvokeVoidAsync("setFocus", Id!); } - public void SetFocus() => _ = SetFocusAsync(); + public void SetFocus() + { + _ = SetFocusAsync(); + } public async Task ShowPickerAsync() { diff --git a/Components/WAInputDateTime.razor b/Components/WAInputDateTime.razor index 023cd58..a441674 100644 --- a/Components/WAInputDateTime.razor +++ b/Components/WAInputDateTime.razor @@ -3,7 +3,7 @@ @using Microsoft.JSInterop @using System.Globalization @typeparam TValue - +@attribute [Obsolete("This component is deprecated. Please use WADateInput instead.")] @inherits WAComponentBase + + @if (CloseIcon is not null || !String.IsNullOrWhiteSpace(CloseIconName)) + { + + } + @if (NextIcon is not null || !String.IsNullOrWhiteSpace(NextIconName)) + { + + } + @if (PreviousIcon is not null || !String.IsNullOrWhiteSpace(PreviousIconName)) + { + + } + @if (ZoomInIcon is not null || !String.IsNullOrWhiteSpace(ZoomInIconName)) + { + + } + @if (ZoomOutIcon is not null || !String.IsNullOrWhiteSpace(ZoomOutIconName)) + { + + } + + @if(Actions is not null) + { + + @Actions + + } + + @ChildContent + + + diff --git a/Components/WALightbox.razor.cs b/Components/WALightbox.razor.cs new file mode 100644 index 0000000..0a80221 --- /dev/null +++ b/Components/WALightbox.razor.cs @@ -0,0 +1,291 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; + +namespace WebAwesomeBlazor.Components +{ + public partial class WALightbox : WAComponentBase + { + #region Parameters + /// + /// The zero-based index of the current item. Set this before opening to choose which item the lightbox starts on. + /// + [Parameter] + public int ItemIndex { get; set; } = 0; + + /// + /// Optional close icon to use instead of the default. Available names depend on the icon library being used. + /// + [Parameter] + public string? CloseIconName { get; set; } + + /// + /// Optional play icon to use instead of the default. + /// + [Parameter] + public Icon? CloseIcon { get; set; } + + /// + /// A label that describes the lightbox to assistive devices, e.g. "Vacation photos". + /// + [Parameter] + public string? Label { get; set; } + /// + /// Wraps around when navigating past the first or last item with the buttons or the keyboard. + /// + [Parameter] + public bool Loop { get; set; } = false; + + /// + /// Optional next icon to use instead of the default. . Available names depend on the icon library being used. + /// + [Parameter] + public string? NextIconName { get; set; } + + /// + /// Optional next icon to use instead of the default. + /// + [Parameter] + public Icon? NextIcon { get; set; } + + /// + /// Optional previous icon to use instead of the default. . Available names depend on the icon library being used. + /// + [Parameter] + public string? PreviousIconName { get; set; } + + /// + /// Optional play icon to use instead of the default. + /// + [Parameter] + public Icon? PreviousIcon { get; set; } + + /// + /// Indicates whether or not the lightbox is open. Use OpenAsync() and CloseAsync() to change the value. + /// + [Parameter] + public bool Open { get; set; } = false; + /// + /// Shows the counter that shows the current item's position. + /// + [Parameter] + public bool ShowCounter { get; set; } = true; + /// + /// Shows the previous and next buttons. When hidden, swiping and the arrow keys still work. The buttons are always hidden on touch screens, where swiping takes their place. + /// + [Parameter] + public bool ShowNavigation { get; set; } = true; + + /// + /// Enables zooming and shows the zoom button. + /// + [Parameter] + public bool ShowZoom { get; set; } = true; + + /// + /// Gets or sets whether thumbnails are displayed. + /// + [Parameter] + public bool ShowThumbnails { get; set; } = false; + /// + /// Optional Zoom In icon to use instead of the default. . Available names depend on the icon library being used. + /// + [Parameter] + public string? ZoomInIconName { get; set; } + + /// + /// Optional Zoom In icon to use instead of the default. + /// + [Parameter] + public Icon? ZoomInIcon { get; set; } + /// + /// Optional zoom out icon to use instead of the default. . Available names depend on the icon library being used. + /// + [Parameter] + public string? ZoomOutIconName { get; set; } + + /// + /// Optional zoom out icon to use instead of the default. + /// + [Parameter] + public Icon? ZoomOutIcon { get; set; } + + /// + /// Emitted when the lightbox opens. Set args.Cancel = true to prevent opening. + /// + [Parameter] + public EventCallback Showing { get; set; } + + /// + /// Emitted when the lightbox is requested to close. Set args.Cancel = false to prevent closing. + /// + [Parameter] + public EventCallback Hiding { get; set; } + + /// + /// Emitted when the current item changes. + /// + [Parameter] + public EventCallback ItemChanged { get; set; } + + /// + /// Emitted after the lightbox opens and all animations are complete. + /// + [Parameter] + public EventCallback Shown { get; set; } + /// + /// Emitted after the lightbox closes and all animations are complete. + /// + [Parameter] + public EventCallback Hidden { get; set; } + /// + /// Extra buttons to show in the lightbox's toolbar, such as download or share. Works best with , which is styled to match the built-in controls + /// + [Parameter] + public RenderFragment? Actions { get; set; } + #endregion + + #region Computed Properties + + #endregion + #region Lifecycle + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + _instance = await SafeInvokeAsync("initialize", Element!, objRef); + } + } + + protected override async ValueTask DisposeAsyncCore(bool disposing) + { + if (disposing) + { + try + { + if (_instance is not null) + await _instance.InvokeVoidAsync("dispose"); + + } + catch (JSDisconnectedException) + { + } + objRef?.Dispose(); + } + } + + protected override async Task OnInitializedAsync() + { + objRef ??= DotNetObjectReference.Create(this); + + await base.OnInitializedAsync(); + } + #endregion + + #region Public Methods + public async Task CloseAsync() + { + Open = false; + await InvokeAsync(StateHasChanged); + } + + /// + /// Shows the next item. + /// + public async Task NextItemAsync() + { + await SafeInvokeVoidAsync("next", Element); + } + + public void NextItem() + { + _ = NextItemAsync(); + } + + public async Task OpenAsync() + { + Open = true; + await InvokeAsync(StateHasChanged); + } + /// + /// Shows the previous item. + /// + public async Task PreviousItemAsync() + { + await SafeInvokeVoidAsync("previous", Element); + } + + public void PreviousItem() + { + _ = PreviousItemAsync(); + } + /// + /// Zooms in on the current image. + /// + public async Task ZoomInAsync() + { + await SafeInvokeVoidAsync("zoomIn", Element); + } + + public void ZoomIn() + { + _ = ZoomInAsync(); + } + /// + /// Zooms out of the current image. + /// + public async Task ZoomOutAsync() + { + await SafeInvokeVoidAsync("zoomOut", Element); + } + + public void ZoomOut() + { + _ = ZoomOutAsync(); + } + + #endregion + #region State + private DotNetObjectReference objRef = default!; + #endregion + + #region Event Handlers + [JSInvokable] + public async Task HandleLightboxShow() + { + + var args = new LightboxShowingEventArgs(); + await Showing.InvokeAsync(args); + return args.Cancel; + } + + [JSInvokable] + public async Task HandleLightboxHide() + { + var args = new LightboxHidingEventArgs(); + await Hiding.InvokeAsync(args); + return args.Cancel; + } + + [JSInvokable] + public async Task HandleItemChange(int index, int prevIndex) + { + await ItemChanged.InvokeAsync(new LightboxItemChangeEventArgs() { Index = index, PreviousIndex = prevIndex }); + } + + [JSInvokable] + public async Task HandleLightboxShown() + { + Open = true; + await Shown.InvokeAsync(); + } + + [JSInvokable] + public async Task HandleLightboxHidden() + { + Open = false; + await Hidden.InvokeAsync(); + } + #endregion + + } +} diff --git a/Components/WALightbox.razor.js b/Components/WALightbox.razor.js new file mode 100644 index 0000000..58e7d80 --- /dev/null +++ b/Components/WALightbox.razor.js @@ -0,0 +1,70 @@ +var showHandled = false; +var hideHandled = false; + +export async function initialize(element, dotnetHelper) { + + if (!element) return null; + + // Capture the handler so we can remove it later + const onShowing = async (event) => { + if (showHandled) { + showHandled = false; + return; + } + event.preventDefault(); + var showcancel = await dotnetHelper.invokeMethodAsync('HandleLightboxShow'); + + if (!showcancel) { + showHandled = true; + element.open = true; + } + }; + + const onItemChange = (event) => { + console.log('itemChange', event); + dotnetHelper.invokeMethodAsync('HandleItemChange', event.detail.index, event.detail.previousIndex) + }; + + const onHiding = async (event) => { + if (hideHandled) { + hideHandled = false; + return; + } + event.preventDefault(); + + var hidecancel = await dotnetHelper.invokeMethodAsync('HandleLightboxHide'); + + if (!hidecancel) { + hideHandled = true; + element.open = false; + } + }; + + const onHide = () => { + dotnetHelper.invokeMethodAsync('HandleLightboxHidden'); + } + + const onShow = () => { + dotnetHelper.invokeMethodAsync('HandleLightboxShown'); + } + + // Register the event listener + element.addEventListener('wa-show', onShowing); + element.addEventListener('wa-hide', onHiding); + element.addEventListener('wa-item-change', onItemChange); + element.addEventListener('wa-after-hide', onHide); + element.addEventListener('wa-after-show', onShow); + + // Return a cleanup object for Blazor to call + return { + dispose: () => { + element.removeEventListener('wa-show', onShowing); + element.removeEventListener('wa-hide', onHiding); + element.removeEventListener('wa-item-change', onItemChange); + element.removeEventListener('wa-after-hide', onHide); + element.removeEventListener('wa-after-show', onShow); + } + }; +} + + diff --git a/Components/WALightboxItem.razor b/Components/WALightboxItem.razor new file mode 100644 index 0000000..bbd4902 --- /dev/null +++ b/Components/WALightboxItem.razor @@ -0,0 +1,23 @@ +@inherits WAComponentBase + + @if (PlayIcon is not null || !String.IsNullOrWhiteSpace(PlayIconName)) + { + + } + @ChildContent + + diff --git a/Components/WALightboxItem.razor.cs b/Components/WALightboxItem.razor.cs new file mode 100644 index 0000000..ac3001c --- /dev/null +++ b/Components/WALightboxItem.razor.cs @@ -0,0 +1,67 @@ +using Microsoft.AspNetCore.Components; + +namespace WebAwesomeBlazor.Components +{ + public partial class WALightboxItem : WAComponentBase + { + #region Parameters + /// + /// Alternative text for the full-size media. Defaults to the slotted thumbnail's alt. + /// + [Parameter] + public string? AltText { get; set; } + /// + /// A plain text caption to show with the item in the lightbox. + /// + [Parameter] + public string? Caption { get; set; } + /// + /// The intrinsic height of the full-size media in pixels. + /// + [Parameter] + public int? Height { get; set; } + /// + /// Optional play icon to use instead of the default. . Available names depend on the icon library being used. + /// + [Parameter] + public string? PlayIconName { get; set; } + + /// + /// Optional play icon to use instead of the default. + /// + [Parameter] + public Icon? PlayIcon { get; set; } + + /// + /// The sizes to use with srcset. When omitted, the lightbox uses the viewport width, and the zoomed width once the image is zoomed in. + /// + [Parameter] + public string? Sizes { get; set; } + /// + /// The URL of the full-size image or video. The thumbnail links to it, so the item still works without JavaScript and when opened in a new tab. + /// + [Parameter] + public string? SourceUrl { get; set; } + /// + /// A set of image sources for the full-size image, in the same format as the srcset attribute. + /// + [Parameter] + public string? SourceSet { get; set; } + /// + /// The URL of a thumbnail to use in the lightbox's thumbnail strip and as a placeholder while the full-size media loads. Only needed when no is slotted in. + /// + [Parameter] + public string? ThumbnailUrl { get; set; } + /// + /// The kind of media the item shows in the lightbox. Videos show a play button over their thumbnail. + /// + [Parameter] + public LightboxItemMediaType MediaType { get; set; } = LightboxItemMediaType.Image; + /// + /// The intrinsic width of the full-size media in pixels. Set this with height so the lightbox can size the slide before the media loads. + /// + [Parameter] + public int? Width { get; set; } + #endregion + } +} diff --git a/Components/WANumberTicker.razor b/Components/WANumberTicker.razor new file mode 100644 index 0000000..c1256a4 --- /dev/null +++ b/Components/WANumberTicker.razor @@ -0,0 +1,24 @@ +@using System.Globalization +@inherits WAComponentBase + + + \ No newline at end of file diff --git a/Components/WANumberTicker.razor.cs b/Components/WANumberTicker.razor.cs new file mode 100644 index 0000000..d8464f6 --- /dev/null +++ b/Components/WANumberTicker.razor.cs @@ -0,0 +1,164 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; + +namespace WebAwesomeBlazor.Components +{ + public partial class WANumberTicker : WAComponentBase + { + #region Parameters + /// + /// The ISO 4217 currency code to use when formatting. + /// + [Parameter] + public string CurrencyCode { get; set; } = "USD"; + /// + /// How to display the currency. + /// + [Parameter] + public NumberTickerCurrencyDisplay CurrencyDisplay { get; set; } = NumberTickerCurrencyDisplay.Symbol; + /// + /// The number of milliseconds to wait before counting from the start value. Later value changes aren't delayed. + /// + [Parameter] + public int Delay { get; set; } = 0; + + /// + /// The longest a count can take, in milliseconds. A count ends early once the number shown stops changing. Set to 0 to skip the animation. + /// + [Parameter] + public int Duration { get; set; } = 2000; + /// + /// Starts counting right away instead of waiting until the ticker scrolls into view. + /// + [Parameter] + public bool Eager { get; set; } = false; + /// + /// The easing function to use for counting. Accepts any CSS easing function, such as linear, ease-in-out, cubic-bezier(), steps(), or linear(). Invalid values fall back to the default. + /// + [Parameter] + public string Easing { get; set; } = "cubic-bezier(0.16, 1, 0.3, 1)"; + /// + /// The maximum number of fraction digits to use. Possible values are 0-100. If only one fraction digit option is set, it's used for both. + /// + [Parameter] + public int? MaximumFractionDigits { get; set; } + /// + /// The minimum number of fraction digits to use. Possible values are 0-100. If only one fraction digit option is set, it's used for both. + /// + [Parameter] + public int? MinimumFractionDigits { get; set; } + /// + /// The maximum number of significant digits to use. Possible values are 1-21. + /// + [Parameter] + public int? MaximumSignificantDigits { get; set; } + /// + /// The minimum number of integer digits to use. Possible values are 1-21. + /// + [Parameter] + public int? MinimumSignificantDigits { get; set; } + /// + /// The number to count from on the first run and when RestartAsync() is called. + /// + [Parameter] + public decimal StartValue { get; set; } = 0; + + /// + /// The formatting style to use. + /// + [Parameter] + public NumberTickerFormatType FormatType { get; set; } = NumberTickerFormatType.Decimal; + /// + /// The number to count to. Once the ticker has started, changing it counts from the number currently displayed to the new value. + /// + [Parameter] + public decimal Value { get; set; } + /// + /// Shows grouping separators + /// + [Parameter] + public bool GroupDigits { get; set; } = true; + + /// + /// Emitted when a running countdown reaches zero. Not emitted when the date had already passed. + /// + [Parameter] + public EventCallback Finished { get; set; } + + #endregion + + #region Computed Properties + + #endregion + #region Lifecycle + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await base.OnAfterRenderAsync(firstRender); + if (firstRender) + { + + _instance = await SafeInvokeAsync("initialize", Element, objRef); + } + } + + protected override async ValueTask DisposeAsyncCore(bool disposing) + { + if (disposing) + { + try + { + if (_instance is not null) + await _instance.InvokeVoidAsync("dispose"); + + } + catch (JSDisconnectedException) + { + } + objRef?.Dispose(); + + } + + } + protected override async Task OnInitializedAsync() + { + objRef ??= DotNetObjectReference.Create(this); + + + AdditionalAttributes ??= new Dictionary(); + + await base.OnInitializedAsync(); + } + #endregion + + #region State + private DotNetObjectReference objRef = default!; + #endregion + + #region Event Handlers + [JSInvokable] + public async Task HandleTickerFinished() + { + await Finished.InvokeAsync(); + } + #endregion + + #region Public Methods + /// + /// Plays the ticker again from startValue to value. + /// + public async Task RestartAsync() + { + await SafeInvokeVoidAsync("restart", Element); + } + + public void Restart() + { + _ = RestartAsync(); + } + + #endregion + + } + + +} diff --git a/Components/WANumberTicker.razor.js b/Components/WANumberTicker.razor.js new file mode 100644 index 0000000..a21bd5b --- /dev/null +++ b/Components/WANumberTicker.razor.js @@ -0,0 +1,28 @@ +// JavaScript for WACounter component +// JavaScript for WACodeHighlighter component +export function initialize(element, dotnetHelper) { + if (!element) return null; + + + // Capture handler so it can be removed later + const onFinished = () => { + dotnetHelper.invokeMethodAsync('HandleTickerFinished'); + }; + + + // Register listener + element.addEventListener('wa-finish', onFinished); + + // Return cleanup object + return { + dispose: () => { + element.removeEventListener('wa-finish', onFinished); + } + }; +} + +export function restart(element) { + if (!element) return; + + element.restart(); +} \ No newline at end of file diff --git a/Components/WARichTextEditor.razor b/Components/WARichTextEditor.razor new file mode 100644 index 0000000..b614783 --- /dev/null +++ b/Components/WARichTextEditor.razor @@ -0,0 +1,46 @@ +@using Microsoft.AspNetCore.Components.Forms +@using System.Linq.Expressions +@using Microsoft.JSInterop + + +@inherits WAComponentBase + + + + diff --git a/Components/WARichTextEditor.razor.cs b/Components/WARichTextEditor.razor.cs new file mode 100644 index 0000000..1a3b383 --- /dev/null +++ b/Components/WARichTextEditor.razor.cs @@ -0,0 +1,503 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.JSInterop; +using System.Linq.Expressions; + +namespace WebAwesomeBlazor.Components +{ + public partial class WARichTextEditor : WAComponentBase + { + #region Parameters + [CascadingParameter] private EditContext EditContext { get; set; } = default!; + /// + /// The value of the editor + /// + [Parameter] + public string Value { get; set; } = default!; + [Parameter] + public EventCallback ValueChanged { get; set; } + + [Parameter] public Expression> ValueExpression { get; set; } = default!; + + /// + /// The plain text value of the editor + /// + [Parameter] + public string PlainTextValue { get; set; } = default!; + [Parameter] + public EventCallback PlainTextValueChanged { get; set; } + [Parameter] + public Expression> PlainTextValueExpression { get; set; } = default!; + + /// + /// Invoked when the editor value has changed and committed. + /// + [Parameter] + public EventCallback Changed { get; set; } + + /// + /// The editor's visual appearance. + /// + [Parameter] + public InputAppearance Appearance { get; set; } = InputAppearance.Outlined; + + + /// + /// Controls whether and how text input is automatically capitalized as it is entered/edited by the user. + /// + [Parameter] + public InputAutoCapitalize? AutoCapitalize { get; set; } + + /// + /// Indicates whether the browser's autocorrect feature is on or off. + /// + [Parameter] + public bool AutoCorrect { get; set; } = true; + + /// + /// Makes the editor disabled. + /// + [Parameter] + public bool Disabled { get; set; } = false; + + /// + /// Used to customize the label or icon of the Enter key on virtual keyboards. + /// + [Parameter] + public InputEnterKeyHint? EnterKeyHint { get; set; } = InputEnterKeyHint.Enter; + + /// + /// The editor's size. + /// + [Parameter] + public InputSize Size { get; set; } = InputSize.Inherit; + + /// + /// The editor's label + /// + [Parameter] + public string? Label { get; set; } + + /// + /// The editor's hint text. + /// + [Parameter] + public string? Hint { get; set; } + + /// + /// Placeholder text to show as a hint when the editor is empty. + /// + [Parameter] + public string? Placeholder { get; set; } + + + /// + /// Makes the editor readonly. + /// + [Parameter] + public bool ReadOnly { get; set; } = false; + + /// + /// Makes the editor a required field. + /// + [Parameter] + public bool Required { get; set; } = false; + + /// + /// Tells the browser what type of data will be entered by the user, allowing it to display the appropriate virtual keyboard on supportive devices. + /// + [Parameter] + public InputInputMode InputMode { get; set; } = InputInputMode.Text; + + /// + /// Enables spell checking on the editor. + /// + [Parameter] + public bool Spellcheck { get; set; } = false; + /// + /// Invoked when the editor receives focus. + /// + [Parameter] + public EventCallback Focused { get; set; } + /// + /// Invoked when the editor loses focus. + /// + [Parameter] + public EventCallback Blurred { get; set; } + + /// + /// Invoked when there is an error retrieving a suggestion list. + /// + [Parameter] + public EventCallback SuggestionError { get; set; } + + /// + /// Invoked when the selected text in the editor has changed. + /// + [Parameter] + public EventCallback SelectionChanged { get; set; } + + + #endregion + + #region Computed Properties + + string AppearanceString => Appearance switch + { + InputAppearance.Filled => "filled", + InputAppearance.Outlined => "outlined", + InputAppearance.FilledOutlined => "filled-outlined", + _ => "outlined" + //Only filled and outlined are valid for inputs + }; + + string SizeString => Size switch + { + InputSize.XSmall => "xs", + InputSize.Small => "s", + InputSize.Medium => "m", + InputSize.Large => "l", + InputSize.XLarge => "xl", + InputSize.Inherit => "inherit", + _ => "m" + }; + + + string AutoCapitaliseString => AutoCapitalize switch + { + InputAutoCapitalize.Off => "off", + InputAutoCapitalize.None => "none", + InputAutoCapitalize.On => "on", + InputAutoCapitalize.Sentences => "sentences", + InputAutoCapitalize.Words => "words", + InputAutoCapitalize.Characters => "characters", + _ => "" + }; + + string EnterKeyHintString => EnterKeyHint switch + { + InputEnterKeyHint.Next => "next", + InputEnterKeyHint.Done => "done", + InputEnterKeyHint.Enter => "enter", + InputEnterKeyHint.Go => "go", + InputEnterKeyHint.Previous => "previous", + InputEnterKeyHint.Search => "search", + InputEnterKeyHint.Send => "send", + null => "", + _ => "", + }; + + string InputModeString => InputMode switch + { + InputInputMode.None => "none", + InputInputMode.Text => "text", + InputInputMode.Decimal => "decimal", + InputInputMode.Numeric => "numeric", + InputInputMode.Telephone => "tel", + InputInputMode.Search => "search", + InputInputMode.Email => "email", + InputInputMode.Url => "url", + _ => "text" + }; + #endregion + + #region Lifecycle + protected override async ValueTask DisposeAsyncCore(bool disposing) + { + if (disposing) + { + try + { + if (_instance is not null) + await _instance.InvokeVoidAsync("dispose"); + } + catch (JSDisconnectedException) + { + } + + objRef?.Dispose(); + + } + + } + + protected override void OnInitialized() + { + objRef ??= DotNetObjectReference.Create(this); + AdditionalAttributes ??= new Dictionary(); + + if (ValueExpression != null) + fieldIdentifier = FieldIdentifier.Create(ValueExpression); + + base.OnInitialized(); + } + + protected override async Task OnAfterRenderAsync(bool FirstRender) + { + if (FirstRender) + { + //await LoadModuleAsync("./_content/WebAwesomeBlazor/Components/WAInput.razor.js"); + _instance = await SafeInvokeAsync("initialize", Id!, objRef, Value); + + } + + + + } + + protected override async Task OnParametersSetAsync() + { + if (!previousValue!.Equals(Value ?? string.Empty)) + { + previousValue = Value ?? string.Empty; + + //set the formatted value and update the plaintext + var plainTextValue = await SafeInvokeAsync("setValue", Id!, Value!); + await PlainTextValueChanged.InvokeAsync(plainTextValue); + } + + } + + #endregion + + #region Event Handlers + [JSInvokable] + public async Task HandleInputClear() + { + await ValueChanged.InvokeAsync(string.Empty); + await PlainTextValueChanged.InvokeAsync(string.Empty); + EditContext?.NotifyFieldChanged(fieldIdentifier); + } + + [JSInvokable] + public async Task HandleInputInput(string value, string plainTextValue) + { + Console.WriteLine($"HandleInputInput. value: {value}, plaintext: {plainTextValue}"); + + await ValueChanged.InvokeAsync(value); + await PlainTextValueChanged.InvokeAsync(plainTextValue); + EditContext?.NotifyFieldChanged(fieldIdentifier); + } + + [JSInvokable] + public async Task HandleInputChange(string value, string plainTextValue) + { + Console.WriteLine($"HandleInputChange. value: {value}, plaintext: {plainTextValue}"); + await Changed.InvokeAsync(value); + } + + [JSInvokable] + public async Task HandleInputFocus() + { + await Focused.InvokeAsync(); + } + + [JSInvokable] + public async Task HandleInputBlur() + { + await Blurred.InvokeAsync(); + } + + [JSInvokable] + public async Task> GetSuggestions(string trigger, string query) + { + var suggestion = suggestions.SingleOrDefault(s => s.Trigger == trigger) ?? throw new("Suggestion trigger not found"); + var suggestionList = await suggestion.InvokeAsync(query); + return suggestionList; + } + + [JSInvokable] + public async Task HandleSuggestionError(RichTextEditorSuggestionError error) + { + Console.WriteLine($"Suggestion error: {error.ErrorMessage}. Request: {error.Trigger} : {error.Query}"); + } + + [JSInvokable] + public async Task HandleSelectionChange() + { + await SelectionChanged.InvokeAsync(); + } + + #endregion + + #region State + private DotNetObjectReference objRef = default!; + private FieldIdentifier fieldIdentifier = default!; + private string previousValue = string.Empty; + + private List suggestions { get; set; } = new(); + + private bool ColorUpdateRequired { get; set; } = false; + private object? textColor; + private object? highlightColor; + private RichTextEditorOptions Options { get; set; } = new RichTextEditorOptions(); + + #endregion + + #region Private Methods + + private async Task OnValueChanged(ChangeEventArgs e) + { + + await SetValueAsync((string)(e.Value ?? string.Empty)); + } + #endregion + #region Public Methods + /// + /// Set the value of the editor + /// + /// The value to set + public async Task SetValueAsync(string value) + { + var plainText = await SafeInvokeAsync("setValue", Element, value); + await ValueChanged.InvokeAsync(value); + await PlainTextValueChanged.InvokeAsync(plainText); + EditContext?.NotifyFieldChanged(fieldIdentifier); + } + + public void SetValue(string value) + { + _ = SetValueAsync(value); + } + + /// + /// Sets focus to the editor + /// + public async Task SetFocusAsync() + { + await SafeInvokeVoidAsync("setFocus", Id!); + } + + public void SetFocus() + { + _ = SetFocusAsync(); + } + + /// + /// Registers a new suggestion trigger and callback source for features such as mentions, tags, or custom autocomplete providers. + /// + /// The suggestion configuration + public async Task AddSuggestionAsync(RichTextEditorSuggestion suggestion) + { + suggestions ??= []; + + if (suggestions.SingleOrDefault(s => s.Trigger == suggestion.Trigger) is not null) return; + + + suggestions.Add(suggestion); + await SafeInvokeVoidAsync("addSuggestion", Element, objRef, suggestion); + + } + /// + /// Replaces the selection with plain text + /// + /// The text to insert + public async Task InsertTextAsync(string text) + { + await SafeInvokeVoidAsync("insertText", Element, text); + } + + public void InsertText(string text) + { + _ = InsertTextAsync(text); + } + + /// + /// Replaces the selection with HTML. Markup the editor doesn't support is stripped + /// + /// The HTML string to insert + public async Task InsertHtmlAsync(string html) + { + await SafeInvokeVoidAsync("insertHtml", Element, html); + } + + public void InsertHtml(string html) + { + _ = InsertHtmlAsync(html); + } + /// + /// Undoes the last edit and returns whether there was one + /// + /// True, if the undo was successful + public async Task UndoAsync() + { + return await SafeInvokeAsync("undo", Element); + } + + /// + /// Redoes the last edit and returns whether there was one + /// + /// True, if the redo was successful + public async Task RedoAsync() + { + return await SafeInvokeAsync("redo", Element); + } + + /// + /// Selects all of the content. Does nothing while the editor is disabled + /// + public async Task SelectAllAsync() + { + await SafeInvokeVoidAsync("selectAll", Element); + } + + public void SelectAll() + { + _ = SelectAllAsync(); + } + + /// + /// Gets the selected text + /// + /// The selected text + public async Task GetSelectedTextAsync() + { + return await SafeInvokeAsync("selectedText", Element); + } + + /// + /// Deletes the selected text + /// + public async Task DeleteSelectedTextAsync() + { + await SafeInvokeVoidAsync("deleteSelection", Element); + } + + public void DeleteSelectedText() + { + _ = DeleteSelectedTextAsync(); + } + + /// + /// Checks whether there's an edit to redo + /// + /// True, if there is an edit to redo + public async Task CanRedoAsync() + { + return await SafeInvokeAsync("canRedo", Element); + } + + /// + /// Checks whether there's an edit to undo + /// + /// True, if there is an edit to undo + public async Task CanUndoAsync() + { + return await SafeInvokeAsync("canUndo", Element); + } + + public async Task SetOptionsAsync(RichTextEditorOptions options) + { + Options = options; + + await SafeInvokeVoidAsync("updateColors", Element, options.TextColors!.GetValue(), options.HighlightColors!.GetValue()); + + await InvokeAsync(StateHasChanged); + } + #endregion + + } + + + +} diff --git a/Components/WARichTextEditor.razor.js b/Components/WARichTextEditor.razor.js new file mode 100644 index 0000000..ae06a5f --- /dev/null +++ b/Components/WARichTextEditor.razor.js @@ -0,0 +1,151 @@ +export async function setValue(elementId, newValue) { + let element = document.getElementById(elementId); + if (!element) return; + + console.log('setting new value', newValue); + element.value = newValue; + + await customElements.whenDefined('wa-rich-text-editor'); + await element.updateComplete; + console.log(element.textValue); + return element.textValue; +} + +export function initialize(elementId, dotnetHelper, setValue) { + const element = document.getElementById(elementId); + if (!element) return null; + + + // Only set the value if explicitly provided + if (setValue !== undefined && setValue !== null) { + element.value = setValue; + } + + // Capture handlers so they can be removed later + + const onChange = () => { + dotnetHelper.invokeMethodAsync('HandleInputChange', element.value, element.textValue); + }; + + const onFocus = () => { + dotnetHelper.invokeMethodAsync('HandleInputFocus'); + }; + + const onBlur = () => { + dotnetHelper.invokeMethodAsync('HandleInputBlur'); + }; + + const onInput = () => { + dotnetHelper.invokeMethodAsync('HandleInputInput', element.value, element.textValue); + }; + + const onSuggestionError = (event) => { + + var errorDetails = { + errorMessage: event.detail.error.message, + query: event.detail.request.query, + trigger: event.detail.request.trigger + } + dotnetHelper.invokeMethodAsync('HandleSuggestionError', errorDetails); + }; + + const onSelectionChanged = () => { + dotnetHelper.invokeMethodAsync('HandleSelectionChange') + }; + + // Register listeners + element.addEventListener('change', onChange); + element.addEventListener('focus', onFocus); + element.addEventListener('blur', onBlur); + element.addEventListener('input', onInput); + element.addEventListener('wa-suggestions-error', onSuggestionError); + element.addEventListener('selectionchange', onSelectionChanged); + // Return cleanup object + return { + dispose: () => { + element.removeEventListener('change', onChange); + element.removeEventListener('focus', onFocus); + element.removeEventListener('blur', onBlur); + element.removeEventListener('input', onInput); + element.removeEventListener('wa-suggestions-error', onSuggestionError); + element.removeEventListener('selectionchange', onSelectionChanged); + } + }; +} + + +export function setFocus(element) { + if (!element) return; + element.focus(); +} + +export async function addSuggestion(element, dotnetHelper, suggestion) { + if (!element) return; + + element.suggestions ??= []; + + element.suggestions.push({ + trigger: suggestion.trigger, + dataSource: ({ query }) => + dotnetHelper.invokeMethodAsync( + 'GetSuggestions', + suggestion.trigger, + query + ) + }); + +} + +export function insertText(element, text) { + if (!element) return; + element.insertText(text); +} + +export function insertHtml(element, html) { + if (!element) return; + element.insertHtml(html); +} + +export function undo(element) { + if (!element) return; + return element.undo(); +} + +export function redo(element) { + if (!element) return; + return element.redo(); +} + +export function selectAll(element) { + if (!element) return; + element.selectAll(); +} + +export function selectedText(element) { + if (!element) return; + return element.selectedText(); +} + +export function deleteSelection(element) { + if (!element) return; + element.deleteSelection(); +} + +export function canRedo(element) { + if (!element) return; + return element.canRedo; +} + +export function canUndo(element) { + if (!element) return; + return element.canUndo; +} + +export function updateColors(element, textColor, highlightColor) { + element.textColors = textColor; + element.highlightColors = highlightColor; +} + + + + diff --git a/Enums.cs b/Enums.cs index 74cb963..42507af 100644 --- a/Enums.cs +++ b/Enums.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using System.ComponentModel; +using System.Text.Json.Serialization; namespace WebAwesomeBlazor { @@ -493,6 +494,40 @@ public enum CopyButtonTooltipMode None } #endregion + #region Counter Enums + public enum CounterDirection + { + [Description("up")] + Up, + [Description("down")] + Down + } + public enum CounterFormat + { + [Description("long")] + Long, + [Description("short")] + Short, + [Description("narrow")] + Narrow + } + + public enum CounterUnit + { + [Description("seconds")] + Seconds, + [Description("minutes")] + Minutes, + [Description("hours")] + Hours, + [Description("days")] + Days, + [Description("months")] + Months, + [Description("years")] + Years + } + #endregion #region DataGrid Enums public enum DataGridAppearance { @@ -838,6 +873,15 @@ public enum LayoutSlots Footer, } #endregion + #region LightboxItem Enums + public enum LightboxItemMediaType + { + [Description("image")] + Image, + [Description("video")] + Video + } + #endregion #region NavTree Enums public enum NavTreeSelection { @@ -876,6 +920,29 @@ public enum NumberInputEnterKeyHint Send } #endregion + #region NumberTicker Enums + public enum NumberTickerFormatType + { + [Description("currency")] + Currency, + [Description("decimal")] + Decimal, + [Description("percent")] + Percent + } + + public enum NumberTickerCurrencyDisplay + { + [Description("symbol")] + Symbol, + [Description("narrowSymbol")] + NarrowSymbol, + [Description("code")] + Code, + [Description("name")] + Name + } + #endregion #region OtpInput Enums public enum OtpAllowedCharacters { @@ -1029,6 +1096,137 @@ public enum RelativeTimeFormat Narrow } #endregion + #region RichTextEditor Enums + public enum RichTextEditorToolbarItem + { + [Description("block")] + Block, + [Description("bold")] + Bold, + [Description("italic")] + Italic, + [Description("underline")] + Underline, + [Description("strikethrough")] + Strikethrough, + [Description("highlight")] + Highlight, + [Description("code")] + Code, + [Description("subscript")] + Subscript, + [Description("superscript")] + Superscript, + [Description("color")] + Color, + [Description("format-menu")] + FormatMenu, + [Description("align")] + Align, + [Description("lists")] + Lists, + [Description("bullet-list")] + BulletList, + [Description("ordered-list")] + OrderedList, + [Description("indent")] + Indent, + [Description("outdent")] + Outdent, + [Description("block-quote")] + BlockQuote, + [Description("code-block")] + CodeBlock, + [Description("link")] + Link, + [Description("image")] + Image, + [Description("embed")] + Embed, + [Description("table")] + Table, + [Description("horizontal-rule")] + HorizontalRule, + [Description("clear-formatting")] + ClearFormatting, + [Description("paste-plain-text")] + PasteAsPlainText, + [Description("undo")] + Undo, + [Description("redo")] + Redo, + [Description("actions")] + CustomActions, + [Description("|")] + Divider + } + public enum RichTextEditorToolbarPlacement + { + [Description("top")] + Top, + [Description("bottom")] + Bottom + } + public enum RichTextEditorFeatureOption + { + [Description("bold")] + Bold, + [Description("italic")] + Italic, + [Description("underline")] + Underline, + [Description("strikethrough")] + Strikethrough, + [Description("highlight")] + Highlight, + [Description("code")] + Code, + [Description("subscript")] + Subscript, + [Description("superscript")] + Superscript, + [Description("color")] + Color, + [Description("link")] + Link, + [Description("image")] + Image, + [Description("embed")] + Embed, + [Description("table")] + Table, + [Description("blockquote")] + BlockQuote, + [Description("code-block")] + CodeBlock, + [Description("bullet-list")] + BulletList, + [Description("ordered-list")] + OrderedList, + [Description("horizontal-rule")] + HorizontalRule, + [Description("align")] + Align, + [Description("lists")] + Lists + } + + public enum RichTextEditorHeadingLevel + { + [Description("1")] + H1, + [Description("2")] + H2, + [Description("3")] + H3, + [Description("4")] + H4, + [Description("5")] + H5, + [Description("6")] + H6 + } + #endregion #region Scroller Enums public enum ScrollerOrientation { @@ -1347,4 +1545,26 @@ public enum VideoPreload } #endregion + + internal static class EnumExtensions + { + extension(Enum e) + { + internal string GetDescription() + { + var field = e.GetType().GetField(e.ToString()); + if (field == null) + return e.ToString(); + + var attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false); + if (Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute) + { + return attribute.Description; + } + + return e.ToString(); + } + } + } + } diff --git a/README.md b/README.md index d665526..6d19478 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ I'm a hobbyist developer. This is an open source project to provide Blazor components for the Web Awesome UI framework. Feedback and contributions are welcome! # WebAwesomeBlazor -Currently supports Web Awesome 3.14.0. +Currently supports Web Awesome 3.15.0. # Changelog -[Version 1.14.0](/docs/CHANGELOG.md) +[Version 1.15.0](/docs/CHANGELOG.md) # Installation Get the latest package from [NuGet](https://www.nuget.org/packages/WebAwesomeBlazor/) @@ -18,8 +18,8 @@ dotnet add package WebAwesomeBlazor ### Free components Add the project code to your `App.razor` or `wwwroot/index.html` file in the `` section along with the extra utility files for this package: ```HTML - - + + ``` ### Web Awesome Pro components @@ -64,13 +64,15 @@ Refer to [IconClass](/docs/IconClass.md) for usage. - [WACallout](/docs/WACallout.md) - [WACard](/docs/WACard.md) - [WACarousel](/docs/WACarousel.md) -- [WACheckboxGroup](/docs/WACheckboxGroup.md) - [WACheckbox](/docs/WACheckbox.md) +- [WACheckboxGroup](/docs/WACheckboxGroup.md) +- [WACodeHighlighter](/docs/WACodeHighlighter.md) - [WAColorPicker](/docs/WAColorPicker.md) - (Pro) [WACombobox](/docs/WACombobox.md) - [WAComboboxOption](/docs/WAComboboxOption.md) - [WAComparison](/docs/WAComparison.md) - [WACopyButton](/docs/WACopyButton.md) +- [WACounter](/docs/WACounter.md) - (Pro) [WADataGrid](/docs/WADataGrid.md) - (Pro) [WADateInput](/docs/WADateInput.md) - (Pro) [WADatePicker](/docs/WADatePicker.md) @@ -85,12 +87,14 @@ Refer to [IconClass](/docs/IconClass.md) for usage. - [WAIcon](/docs/WAIcon.md) - [WAInclude](/docs/WAInclude.md) - [WAInput](/docs/WAInput.md) -- [WAInputDateTime](/docs/WAInputDateTime.md) +- (Deprecated) [WAInputDateTime](/docs/WAInputDateTime.md) - [WAInputNumber](/docs/WAInputNumber.md) - [WAIntersectionObserver](/docs/WAIntersectionObserver.md) - [WAKnownDate](/docs/WAKnownDate.md) +- [WALightbox](/docs/WALightbox.md) - [WAMarkdown](/docs/WAMarkdown.md) - [WANumberInput](/docs/WANumberInput.md) +- [WANumberTicker](/docs/WANumberTicker.md) - [WAOTPInput](/docs/WAOTPInput.md) - [WAPage](/docs/WAPage.md) - [WALayoutContent](/docs/WALayoutContent.md) @@ -105,6 +109,7 @@ Refer to [IconClass](/docs/IconClass.md) for usage. - [WARating](/docs/WARating.md) - [WARelativeTime](/docs/WARelativeTime.md) - [WAResizeObserver](/docs/WAResizeObserver.md) +- (Pro) [WARichTextEditor](/docs/WARichTextEditor.md) - [WAScroller](/docs/WAScroller.md) - [WASelect](/docs/WASelect.md) - [WASelectOption](/docs/WASelectOption.md) diff --git a/WebAwesomeBlazor.csproj b/WebAwesomeBlazor.csproj index 3be3040..4929563 100644 --- a/WebAwesomeBlazor.csproj +++ b/WebAwesomeBlazor.csproj @@ -5,7 +5,7 @@ enable enable true - 1.14.0 + 1.15.0 WebAwesomeBlazor Web Awesome Blazor https://github.com/jaysonb485/WebAwesome/ @@ -31,6 +31,7 @@ + diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index abd4d4d..4cd05ad 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## Version 1.15.0 +- Upgraded to [Web Awesome 3.15.0](https://webawesome.com/docs/resources/changelog#wa_3150) - Make sure you have updated your project version on [Web Awesome Teams](https://webawesome.com/teams), and update the versions in your `App.razor` file. +- Fix missing Focused and Blurred event callbacks on [WADateInput](/docs/WADateInput.md) +- Deprecated [WAInputDateTime](/docs/WAInputDateTime.md) component - use [WADateInput](/docs/WADateInput.md) instead. +- New components: + - [WARichTextEditor](/docs/WARichTextEditor.md) + - [WALightbox](/docs/WALightbox.md) + - [WACodeHighlighter](/docs/WACodeHighlighter.md) + - [WACounter](/docs/WACounter.md) + - [WANumberTicker](/docs/WANumberTicker.md) + ## Version 1.14.0 - Upgraded to [Web Awesome 3.14.0](https://webawesome.com/docs/resources/changelog#wa_3140) - Make sure you have updated your project version on [Web Awesome Teams](https://webawesome.com/teams), and update the versions in your `App.razor` file. - New component [WAStepper](/docs/WAStepper.md) and associated [WAStep](/docs/WAStep.md) to allow users to navigate through a sequence of steps in a process. diff --git a/docs/READMENuget.md b/docs/READMENuget.md index af6ac0e..1e6c1ce 100644 --- a/docs/READMENuget.md +++ b/docs/READMENuget.md @@ -2,7 +2,7 @@ I'm a hobbyist developer. This is an open source project to provide Blazor components for the Web Awesome UI framework. Feedback and contributions are welcome! -Currently supports Web Awesome 3.14.0. +Currently supports Web Awesome 3.15.0. ## Changelog [Changelog](https://github.com/jaysonb485/WebAwesome/blob/master/docs/CHANGELOG.md) diff --git a/docs/WACodeHighlighter.md b/docs/WACodeHighlighter.md new file mode 100644 index 0000000..1245da8 --- /dev/null +++ b/docs/WACodeHighlighter.md @@ -0,0 +1,53 @@ +# WACodeHighlighter +## WebAwesomeBlazor.Components.WACodeHighlighter + +```HTML+Razor + +``` + +### Description +Code highlighters display syntax-highlighted code with a copy button. Use them for code samples, install commands, and configuration snippets. + +[Web Awesome docs](https://webawesome.com/docs/components/code-highlighter) + +### Properties +| Property | Type | Default | Description | +|----------|------|---------|-------------| +| `Code` | `string?` | `null` | The code to display. When provided, it takes precedence over `ChildContent` and is rendered exactly as supplied without dedenting. Useful for dynamic code or content that would otherwise require extensive escaping. | +| `Label` | `string?` | `null` | Accessible label used to describe the code region. When omitted, a localized "Code" label is used. | +| `CodeLanguage` | `string?` | `null` | Specifies the language used for syntax highlighting, such as `html`, `css`, `js`, or `python`. Leave empty to display plain text without highlighting. | +| `ShowCopyButton` | `bool` | `true` | Shows a button that allows users to copy the displayed code to the clipboard. | +| `Dedent` | `bool` | `true` | Removes common leading indentation from `ChildContent` before rendering. Disable to preserve the content exactly as written. | +| `Wrap` | `bool` | `false` | Wraps long lines instead of displaying a horizontal scrollbar. | +| `GrammarError` | `EventCallback` | - | Invoked when no syntax grammar is available for the specified language. The code is rendered as plain text. | +| `Loaded` | `EventCallback` | - | Invoked after the language grammar has loaded and syntax highlighting has been applied. | + +### Examples + +#### Basic Usage +```HTML+Razor + + <wa-button variant="brand"> + <wa-icon slot="start" name="rocket"></wa-icon> + Launch + </wa-button> + +``` + +```HTML+Razor + + +@code +{ + string RustCode = """ + fn main() + { + let crabs = ["Ferris", "Sebastian", "Mr. Krabs"]; + + for crab in crabs.iter() { + println!("Hello, {crab}!"); + } + } + """; +} +``` \ No newline at end of file diff --git a/docs/WACounter.md b/docs/WACounter.md new file mode 100644 index 0000000..615729c --- /dev/null +++ b/docs/WACounter.md @@ -0,0 +1,64 @@ +# WACounter +## WebAwesomeBlazor.Components.WACounter + +```HTML+Razor + +``` + +### Description +Counters count down to a date or up from one, ticking through years, months, days, and smaller units. Use them for launch countdowns, sale timers, and showing how long something has been running. + +[Web Awesome docs](https://webawesome.com/docs/components/counter) + +### Properties + +| Property | Type | Default | Description | +|----------|------|---------|-------------| +| `DateTimeValue` | `DateTime?` | `null` | The date and time from which the counter calculates elapsed or remaining time. When not specified, the current date and time are used. Setting this value during rendering may reset the counter. | +| `Delimiter` | `string?` | `""` | Text displayed between units, such as `:`. | +| `Direction` | `CounterDirection` | `Down` | Determines whether the counter counts down to a date or counts up from it. | +| `Duration` | `int?` | `null` | The duration, in milliseconds, to count down from when the component is first rendered. Ignored when `DateTimeValue` is set or when `Direction` is `Up`. | +| `Format` | `CounterFormat` | `Long` | Controls the display format of unit labels. | +| `Label` | `string?` | `null` | Accessible label used to describe the counter to assistive technologies. | +| `LargestUnit` | `CounterUnit` | `Days` | The largest time unit displayed by the counter. Time exceeding this unit is rolled into it. | +| `Paused` | `bool` | `false` | Indicates whether the counter is paused. Use `PauseAsync()` and `UnpauseAsync()` to change the running state programmatically. | +| `SmallestUnit` | `CounterUnit` | `Seconds` | The smallest time unit displayed by the counter. Any time below this unit is discarded. | +| `ShowLabels` | `bool` | `true` | Shows or hides the unit labels. | +| `DaysContent` | `RenderFragment?` | `null` | Custom content used for the days label. | +| `HoursContent` | `RenderFragment?` | `null` | Custom content used for the hours label. | +| `MinutesContent` | `RenderFragment?` | `null` | Custom content used for the minutes label. | +| `SecondsContent` | `RenderFragment?` | `null` | Custom content used for the seconds label. | +| `MonthsContent` | `RenderFragment?` | `null` | Custom content used for the months label. | +| `YearsContent` | `RenderFragment?` | `null` | Custom content used for the years label. | +| `FinishedContent` | `RenderFragment?` | `null` | Content displayed when a countdown reaches zero or when the target date has already passed. | +| `Finished` | `EventCallback` | - | Invoked when an active countdown reaches zero. Not raised when the target date has already passed before rendering. | + +### Methods + +| Method | Parameters | Description | +|----------|----------|-------------| +| `PauseAsync` | None | Pauses the counter, preventing it from advancing until resumed. | +| `UnpauseAsync` | None | Resumes a paused counter. | + +### Examples + +#### Basic Usage +```HTML+Razor + +``` + +#### Customer labels and finish content +```HTML+Razor + + + Minutes + + + Seconds + + + Times up! + + + +``` \ No newline at end of file diff --git a/docs/WALightBox.md b/docs/WALightBox.md new file mode 100644 index 0000000..ae28b3e --- /dev/null +++ b/docs/WALightBox.md @@ -0,0 +1,146 @@ +# WALightbox +## WebAwesomeBlazor.Components.WALightbox + +```HTML+Razor + + + + +``` + +### Description +Lightboxes show images and videos in a full-screen viewer that opens from their thumbnails. Use them for photo galleries, product images, or any media that deserves a closer look. + +[Web Awesome docs](https://webawesome.com/docs/components/lightbox/) + +### Properties +| Property | Type | Default | Description | +|----------|------|---------|-------------| +| `ItemIndex` | `int` | `0` | The zero-based index of the currently displayed item. Set this before opening the lightbox to control which item is shown first. | +| `CloseIconName` | `string?` | `null` | The name of a custom close icon. Available icon names depend on the configured icon library. | +| `CloseIcon` | `Icon?` | `null` | A custom close icon to display instead of the default icon. | +| `Label` | `string?` | `null` | Accessible label used by assistive technologies to describe the lightbox. | +| `Loop` | `bool` | `false` | Enables continuous navigation by wrapping from the last item back to the first, and vice versa. | +| `NextIconName` | `string?` | `null` | The name of a custom next-navigation icon. Available icon names depend on the configured icon library. | +| `NextIcon` | `Icon?` | `null` | A custom next-navigation icon to display instead of the default icon. | +| `PreviousIconName` | `string?` | `null` | The name of a custom previous-navigation icon. Available icon names depend on the configured icon library. | +| `PreviousIcon` | `Icon?` | `null` | A custom previous-navigation icon to display instead of the default icon. | +| `Open` | `bool` | `false` | Indicates whether the lightbox is open and visible. Use `OpenAsync()` and `CloseAsync()` to change the value. | +| `ShowCounter` | `bool` | `true` | Displays a counter showing the current item's position within the collection. | +| `ShowNavigation` | `bool` | `true` | Shows the previous and next navigation buttons. Keyboard navigation and swipe gestures remain available when disabled. | +| `ShowZoom` | `bool` | `true` | Enables zoom functionality and displays zoom controls. | +| `ShowThumbnails` | `bool` | `false` | Displays item thumbnails for quick navigation between items. | +| `ZoomInIconName` | `string?` | `null` | The name of a custom zoom-in icon. Available icon names depend on the configured icon library. | +| `ZoomInIcon` | `Icon?` | `null` | A custom zoom-in icon to display instead of the default icon. | +| `ZoomOutIconName` | `string?` | `null` | The name of a custom zoom-out icon. Available icon names depend on the configured icon library. | +| `ZoomOutIcon` | `Icon?` | `null` | A custom zoom-out icon to display instead of the default icon. | +| `Showing` | `EventCallback` | - | Invoked before the lightbox opens. Set `args.Cancel = true` to prevent opening. | +| `Hiding` | `EventCallback` | - | Invoked before the lightbox closes. Set `args.Cancel = true` to prevent closing. | +| `ItemChanged` | `EventCallback` | - | Invoked whenever the currently displayed item changes. | +| `Shown` | `EventCallback` | - | Invoked after the lightbox has opened and all animations have completed. | +| `Hidden` | `EventCallback` | - | Invoked after the lightbox has closed and all animations have completed. | +| `Actions` | `RenderFragment?` | `null` | Custom content rendered in the lightbox toolbar, typically used for actions such as download, share, or custom commands. | + +### WALightboxItem Properties +| Property | Type | Default | Description | +|----------|------|---------|-------------| +| `AltText` | `string?` | `null` | Alternative text for the full-size media. When not specified, the thumbnail image's alt text is used. | +| `Caption` | `string?` | `null` | Plain text caption displayed with the item in the lightbox. | +| `Height` | `int?` | `null` | The intrinsic height of the full-size media in pixels. | +| `PlayIconName` | `string?` | `null` | The name of a custom play icon. Available icon names depend on the configured icon library. | +| `PlayIcon` | `Icon?` | `null` | A custom play icon to display instead of the default icon for video items. | +| `Sizes` | `string?` | `null` | Specifies responsive image sizes for use with `SourceSet`. When omitted, the viewport width and zoomed width are used automatically. | +| `SourceUrl` | `string?` | `null` | The URL of the full-size image or video displayed by the lightbox. | +| `SourceSet` | `string?` | `null` | A set of image sources in the same format as the HTML `srcset` attribute, enabling responsive image selection. | +| `ThumbnailUrl` | `string?` | `null` | The URL of the thumbnail image used in the thumbnail strip and as a placeholder while the full-size media loads. | +| `MediaType` | `LightboxItemMediaType` | `Image` | Specifies whether the item represents an image or video. Video items display a play button overlay. | +| `Width` | `int?` | `null` | The intrinsic width of the full-size media in pixels. Set together with `Height` to allow the lightbox to size the slide before the media loads. | + +### Methods + +| Method | Parameters | Description | +|----------|----------|-------------| +| `CloseAsync` | None | Closes the lightbox. | +| `NextItemAsync` | None | Navigates to the next item in the collection. | +| `OpenAsync` | None | Opens the lightbox. | +| `PreviousItemAsync` | None | Navigates to the previous item in the collection. | +| `ZoomInAsync` | None | Zooms in on the currently displayed image or content. | +| `ZoomOutAsync` | None | Zooms out of the currently displayed image or content. | + + +### Examples + +#### Basic Usage +```HTML+Razor + + + The sun shines on the mountains and trees + + + A river winding through an evergreen forest + + + The sun is setting over a lavender field + + + A field of grass with the sun setting in the background + + + +``` + +#### Prevent showing +```HTML+Razor + + + +@* ... Lightbox items ... *@ + + + + + + +@code +{ + bool preventShow { get; set; } + + async Task LightboxShowing(LightboxShowingEventArgs args) + { + // Only allow showing the lightbox if the Prevent showing checkbox is not checked. + args.Cancel = preventShow; + } +} +``` \ No newline at end of file diff --git a/docs/WANumberTicker.md b/docs/WANumberTicker.md new file mode 100644 index 0000000..ac02154 --- /dev/null +++ b/docs/WANumberTicker.md @@ -0,0 +1,64 @@ +# WANumberTicker +## WebAwesomeBlazor.Components.WANumberTicker + +```HTML+Razor + +``` + +### Description +Number tickers count up or down to a value when they scroll into view and format it with the Intl.NumberFormat API. Use them for dashboard stats, landing page metrics, and running totals. + +[Web Awesome docs](https://webawesome.com/docs/components/number-ticker) + +### Properties + +| Property | Type | Default | Description | +|----------|------|---------|-------------| +| `CurrencyCode` | `string` | `"USD"` | The ISO 4217 currency code used when formatting currency values. | +| `CurrencyDisplay` | `NumberTickerCurrencyDisplay` | `Symbol` | Determines how currency values are displayed, such as by symbol, code, or name. | +| `Delay` | `int` | `0` | The number of milliseconds to wait before the initial counting animation begins. Subsequent value changes are not delayed. | +| `Duration` | `int` | `2000` | The maximum duration, in milliseconds, of the counting animation. Set to `0` to disable animation and display the target value immediately. | +| `Eager` | `bool` | `false` | Starts counting immediately instead of waiting for the ticker to scroll into view. | +| `Easing` | `string` | `"cubic-bezier(0.16, 1, 0.3, 1)"` | The CSS easing function used by the counting animation. Invalid values fall back to the default easing function. | +| `MaximumFractionDigits` | `int?` | `null` | The maximum number of fractional digits to display. Valid values range from `0` to `100`. | +| `MinimumFractionDigits` | `int?` | `null` | The minimum number of fractional digits to display. Valid values range from `0` to `100`. | +| `MaximumSignificantDigits` | `int?` | `null` | The maximum number of significant digits to display. Valid values range from `1` to `21`. | +| `MinimumSignificantDigits` | `int?` | `null` | The minimum number of significant digits to display. Valid values range from `1` to `21`. | +| `StartValue` | `decimal` | `0` | The value from which counting begins on the initial run and whenever the ticker is restarted. | +| `FormatType` | `NumberTickerFormatType` | `Decimal` | Specifies the formatting style used when displaying the value, such as decimal, currency, or percentage. | +| `Value` | `decimal` | `0` | The target value to count towards. Once started, changes animate from the currently displayed value to the new value. | +| `GroupDigits` | `bool` | `true` | Displays digit grouping separators according to the current locale, such as thousands separators. | +| `Finished` | `EventCallback` | - | Invoked when the counting animation completes and the target value has been reached. | + +### Methods +| Method | Parameters | Description | +|-------------|------------------|------------------------------------------| +| Restart Async | | Restarts the ticker from the StartValue | + +### Examples + +#### Basic Usage +```HTML+Razor + +``` + +#### Currency formatting +```HTML+Razor + +``` + +#### ValueFormatter +A custom formatting function to apply to the number. When set, the formatting properties are ignored. Must be set with JavaScript. + +```HTML+Razor + + +``` \ No newline at end of file diff --git a/docs/WARichTextEditor.md b/docs/WARichTextEditor.md new file mode 100644 index 0000000..63c8755 --- /dev/null +++ b/docs/WARichTextEditor.md @@ -0,0 +1,172 @@ +# Component Name +## WebAwesomeBlazor.Components.WARichTextEditor + +```HTML+Razor + +``` + +### Description +Rich text editors let users write and format content with a toolbar and keyboard shortcuts, and submit the result as HTML like a textarea. + +[Web Awesome docs](https://webawesome.com/docs/components/rich-text-editor) + +### Properties + +| Property | Type | Default | Description | +|----------|------|---------|-------------| +| `Value` | `string` | `null` | The HTML/content value of the editor. Supports two-way binding via `@bind-Value`. | +| `PlainTextValue` | `string` | `null` | The plain text representation of the editor content. Supports two-way binding via `@bind-PlainTextValue`. | +| `Changed` | `EventCallback` | - | Invoked when the editor value has been committed by the user. | +| `Appearance` | `InputAppearance` | `Outlined` | Controls the visual appearance of the editor. | +| `AutoCapitalize` | `InputAutoCapitalize?` | `null` | Controls whether and how text is automatically capitalised while typing. | +| `AutoCorrect` | `bool` | `true` | Enables or disables the browser's autocorrect functionality. | +| `Disabled` | `bool` | `false` | Disables user interaction with the editor. | +| `EnterKeyHint` | `InputEnterKeyHint?` | `Enter` | Customises the label or icon displayed for the Enter key on supported virtual keyboards. | +| `Size` | `InputSize` | `Inherit` | Controls the overall size of the editor. | +| `Label` | `string?` | `null` | Label displayed for the editor. | +| `Hint` | `string?` | `null` | Additional hint text displayed below the editor. | +| `Placeholder` | `string?` | `null` | Placeholder text displayed when the editor is empty. | +| `ReadOnly` | `bool` | `false` | Makes the editor read-only while still allowing content selection and interaction with the content. | +| `Required` | `bool` | `false` | Indicates that a value is required for validation. | +| `InputMode` | `InputInputMode` | `Text` | Provides a hint to the browser about the type of data being entered, allowing it to display an appropriate virtual keyboard on supported devices. | +| `Spellcheck` | `bool` | `false` | Enables browser spell checking within the editor. | +| `Focused` | `EventCallback` | - | Invoked when the editor receives focus. | +| `Blurred` | `EventCallback` | - | Invoked when the editor loses focus. | +| `SuggestionError` | `EventCallback` | - | Invoked when an error occurs while retrieving suggestions. Provides the `ErrorMessage`, the `Trigger` used, and the `Query` entered by the user. | +| `SelectionChanged` | `EventCallback` | - | Invoked when the current text selection within the editor changes. | + +### Methods + +| Method | Parameters | Description | +|----------|----------|-------------| +| `SetValueAsync` | `value: string` | Sets the editor value and updates both the HTML and plain text representations. Triggers value binding and form validation updates. | +| `SetFocusAsync` | None | Sets keyboard focus to the editor. | +| `AddSuggestionAsync` | `suggestion: RichTextEditorSuggestion` | Registers a new suggestion trigger and callback source for features such as mentions, tags, or custom autocomplete providers. See usage in examples below. | +| `InsertTextAsync` | `text: string` | Replaces the current selection with plain text. | +| `InsertHtmlAsync` | `html: string` | Replaces the current selection with HTML content. Unsupported markup is automatically removed. | +| `UndoAsync` | None | Undoes the most recent edit and returns whether an undo operation was available. | +| `RedoAsync` | None | Redoes the most recently undone edit and returns whether a redo operation was available. | +| `SelectAllAsync` | None | Selects all content within the editor. Has no effect when the editor is disabled. | +| `GetSelectedTextAsync` | None | Returns the currently selected text. | +| `DeleteSelectedTextAsync` | None | Removes the currently selected text from the editor. | +| `CanRedoAsync` | None | Returns whether a redo operation is currently available. | +| `CanUndoAsync` | None | Returns whether an undo operation is currently available. | +| `SetOptionsAsync` | `options: RichTextEditorOptions` | Sets the display and editing options for the editor. | + +#### RichTextEditorOptions +| Property | Type | Default | Description | +|----------|------|---------|-------------| +| `DisabledFeatures` | `RichTextEditorFeatures` | `new()` | Features to remove from the editor. Disabled features have their toolbar buttons, keyboard shortcuts, input rules, and pasted content support removed. Content using disabled features is automatically stripped from the editor value. Provided as a list of `RichTextEditorFeatureOptions` | +| `UseMarkdown` | `bool` | `false` | Stores the editor value in Markdown format instead of HTML. | +| `HeadingLevels` | `RichTextEditorHeadingLevel[]` | `RichTextEditorHeadingLevel.H1`, `RichTextEditorHeadingLevel.H2`, `RichTextEditorHeadingLevel.H3` | Determines which heading levels users can apply. Unsupported heading levels are converted to the nearest permitted level. Set all levels to false or provide an empty collection to remove heading support. Provided as a list of `RichTextEditorHeadingLevel` | +| `HighlightColors` | `RichTextEditorColorOptions?` | `null` | Defines the highlight colours available in the colour picker. Provide as either a semicolon-separated list of CSS colors, a string array, or `List{ new EditorColor(CSSStringValue, DisplayLabel), ...}` | +| `IconLibrary` | `string` | `"system"` | Specifies the icon library used for toolbar and popover icons. Use a registered icon library to integrate custom icon sets such as Font Awesome. | +| `LinkRel` | `string` | `""` | Specifies the `rel` attribute applied to links created within the editor. Overrides the default value applied by the target setting. | +| `LinkTarget` | `string` | `""` | Specifies the `target` attribute applied to links created within the editor. When set to `_blank`, `noopener noreferrer` is automatically added. | +| `MaxLength` | `int?` | `null` | The maximum number of plain text characters allowed for validation. Users can continue typing beyond this limit, but the editor becomes invalid. | +| `MinLength` | `int?` | `null` | The minimum number of plain text characters required for validation. | +| `TextColors` | `RichTextEditorColorOptions?` | `null` | Defines the text colours available in the colour picker. Provide as either a semicolon-separated list of CSS colors, a string array, or `List{ new EditorColor(CSSStringValue, DisplayLabel), ...}` | +| `Toolbar` | `RichTextEditorToolbarOptions` | `[]` | Defines which tools are displayed in the editor toolbar and the order in which they appear. Provided as a list of `RichTextEditorToolbarItem` | +| `ToolbarPlacement` | `RichTextEditorToolbarPlacement` | `Top` | Determines where the toolbar is displayed relative to the editor, top or bottom. | +| `AutoLink` | `bool` | `true` | Automatically converts recognised URLs into links as users type. | +| `ShowCount` | `bool` | `false` | Displays a character count below the editor. When `MaxLength` is set, displays the remaining character count instead. | +| `DisableMarkdownShortcuts` | `bool` | `false` | Disables Markdown-style input shortcuts such as headings (`#`), lists (`-`), and highlights (`==text==`). Keyboard shortcuts remain available. | +| `DisableSmartPunctuation` | `bool` | `false` | Disables smart punctuation features such as automatic quotation marks and replacement of `...` and `--` with typographic equivalents. | + +### Examples + +#### Basic Usage +```HTML+Razor + +``` + +#### Setting editor options +```HTML+Razor + + +@code +{ + WARichTextEditor richTextEditor = default!; + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + var editorOptions = new RichTextEditorOptions() + { + TextColors = + new List + { + new EditorColor("#FF0000", "Red"), + new EditorColor("#00FF00", "Green"), + new EditorColor("#0000FF", "Blue") + }, + HighlightColors = "rgb(248 113 113 / 40%); rgb(251 146 60 / 40%); rgb(250 204 21 / 40%); ", + DisabledFeatures = + [ + RichTextEditorFeatureOption.Bold, + RichTextEditorFeatureOption.BulletList + ], + HeadingLevels = + [ + RichTextEditorHeadingLevel.H1, + RichTextEditorHeadingLevel.H2, + RichTextEditorHeadingLevel.H3, + RichTextEditorHeadingLevel.H4, + ], + Toolbar = + [ + RichTextEditorToolbarItem.Align, + RichTextEditorToolbarItem.Divider, + RichTextEditorToolbarItem.Bold, + RichTextEditorToolbarItem.Italic, + RichTextEditorToolbarItem.Underline, + RichTextEditorToolbarItem.Divider, + RichTextEditorToolbarItem.Color, + RichTextEditorToolbarItem.Divider, + RichTextEditorToolbarItem.Undo, + RichTextEditorToolbarItem.Redo + ], + UseMarkdown = true + }; + await richTextEditor.SetOptionsAsync(editorOptions); + } + + } +``` + +#### Providing a suggestion list +```HTML+Razor + + +@code +{ + WARichTextEditor richTextEditor = default!; + List suggestions = new() + { + new RichTextEditorSuggestionItem(){ Label = "John", Description = "IT Manager", Value="1"}, + new RichTextEditorSuggestionItem(){ Label = "Jerry", Description = "CEO", Value="2"}, + new RichTextEditorSuggestionItem(){ Label = "Kerry", Description = "Customer Service Agent", Value="3"}, + new RichTextEditorSuggestionItem(){ Label = "Kat", Description = "Customer Service Agent", Value="4"}, + new RichTextEditorSuggestionItem(){ Label = "Kate", Description = "CS Lead", Value="5"}, + new RichTextEditorSuggestionItem(){ Label = "Kath", Description = "Customer Service Agent", Value="6"}, + new RichTextEditorSuggestionItem(){ Label = "Kathryn", Description = "Customer Service Agent", Value="7"}, + new RichTextEditorSuggestionItem(){ Label = "Katlyn", Description = "Customer Service Agent", Value="8"}, + new RichTextEditorSuggestionItem(){ Label = "Alex", Description = "Customer Service Manager", Value="9"}, + }; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if(firstRender) await richTextEditor.AddSuggestionAsync(new(trigger: "@", function: (async query => await GetSuggestions(query)))); + } + + async Task> GetSuggestions(string query) + { + return suggestions + .OrderBy(name => name.Label) + .Where(name => name.Label.Contains(query, StringComparison.InvariantCultureIgnoreCase)) + .Take(5) + .ToList(); + } +} + +``` \ No newline at end of file diff --git a/docs/_docsTemplate.md b/docs/_docsTemplate.md index 5a179df..565c8e8 100644 --- a/docs/_docsTemplate.md +++ b/docs/_docsTemplate.md @@ -8,7 +8,7 @@ ### Description A brief description of what the Component Name does and its purpose within the Vengage WebAwesome library. -[WebAwesome docs](https://webawesome.com/docs/component) +[Web Awesome docs](https://webawesome.com/docs/component) ### Properties | Property | Type | Default | Description |