Skip to content

Commit

Permalink
Added HtmlHxText elements, Added HtmlSelect/HtmlOption elements
Browse files Browse the repository at this point in the history
  • Loading branch information
carldebilly committed Sep 5, 2021
1 parent 56d812b commit 2a74183
Show file tree
Hide file tree
Showing 6 changed files with 511 additions and 17 deletions.
59 changes: 42 additions & 17 deletions UI/HtmlControls/HtmlControls.Shared/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,50 @@
xmlns:html="using:HtmlControls"
mc:Ignorable="d">

<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="20" Spacing="6">
<TextBlock FontSize="20">HtmlTimePicker <Span FontWeight="Bold">&lt;input type='time' /&gt;</Span></TextBlock>
<html:HtmlTimePicker HorizontalAlignment="Left" x:Name="time1" />
<html:HtmlTimePicker HorizontalAlignment="Left" x:Name="time2" Time="{Binding Time, ElementName=time1, Mode=TwoWay}" />
<ScrollViewer>
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="20" Spacing="6">
<TextBlock FontSize="20">HtmlTimePicker <Span FontWeight="Bold">&lt;input type='time' /&gt;</Span></TextBlock>
<html:HtmlTimePicker HorizontalAlignment="Left" x:Name="time1" />
<html:HtmlTimePicker HorizontalAlignment="Left" x:Name="time2" Time="{Binding Time, ElementName=time1, Mode=TwoWay}" />

<TextBlock FontSize="20">HtmlDatePicker <Span FontWeight="Bold">&lt;input type='date' /&gt;</Span></TextBlock>
<html:HtmlDatePicker HorizontalAlignment="Left" x:Name="date1" />
<html:HtmlDatePicker HorizontalAlignment="Left" x:Name="date2" Date="{Binding Date, ElementName=date1, Mode=TwoWay}" />
<TextBlock FontSize="20">HtmlDatePicker <Span FontWeight="Bold">&lt;input type='date' /&gt;</Span></TextBlock>
<html:HtmlDatePicker HorizontalAlignment="Left" x:Name="date1" />
<html:HtmlDatePicker HorizontalAlignment="Left" x:Name="date2" Date="{Binding Date, ElementName=date1, Mode=TwoWay}" />

<TextBlock FontSize="20">HtmlNumberInput <Span FontWeight="Bold">&lt;input type='number' /&gt;</Span></TextBlock>
<html:HtmlNumberInput HorizontalAlignment="Left" x:Name="number1" />
<html:HtmlNumberInput HorizontalAlignment="Left" x:Name="number2" Value="{Binding Value, ElementName=number1, Mode=TwoWay}" />
<TextBlock FontSize="20">HtmlNumberInput <Span FontWeight="Bold">&lt;input type='number' /&gt;</Span></TextBlock>
<html:HtmlNumberInput HorizontalAlignment="Left" x:Name="number1" />
<html:HtmlNumberInput HorizontalAlignment="Left" x:Name="number2" Value="{Binding Value, ElementName=number1, Mode=TwoWay}" />

<TextBlock FontSize="20">HtmlColorPicker <Span FontWeight="Bold">&lt;input type='color' /&gt;</Span></TextBlock>
<html:HtmlColorPicker HorizontalAlignment="Left" x:Name="color1" />
<html:HtmlColorPicker HorizontalAlignment="Left" x:Name="color2" Color="{Binding Color, ElementName=color1, Mode=TwoWay}" />
<TextBlock FontSize="20">HtmlColorPicker <Span FontWeight="Bold">&lt;input type='color' /&gt;</Span></TextBlock>
<html:HtmlColorPicker HorizontalAlignment="Left" x:Name="color1" />
<html:HtmlColorPicker HorizontalAlignment="Left" x:Name="color2" Color="{Binding Color, ElementName=color1, Mode=TwoWay}" />

<TextBlock FontSize="20">HtmlRangeInput <Span FontWeight="Bold">&lt;input type='range' /&gt;</Span></TextBlock>
<html:HtmlRangeInput HorizontalAlignment="Left" x:Name="range1" />
<html:HtmlRangeInput HorizontalAlignment="Left" x:Name="range2" Value="{Binding Value, ElementName=range1, Mode=TwoWay}" />
</StackPanel>
<TextBlock FontSize="20">HtmlRangeInput <Span FontWeight="Bold">&lt;input type='range' /&gt;</Span></TextBlock>
<html:HtmlRangeInput HorizontalAlignment="Left" x:Name="range1" Value="25" />
<html:HtmlRangeInput HorizontalAlignment="Left" x:Name="range2" Value="{Binding Value, ElementName=range1, Mode=TwoWay}" />

<TextBlock FontSize="20">HtmlProgress <Span FontWeight="Bold">&lt;progress/&gt;</Span></TextBlock>
<html:HtmlProgress HorizontalAlignment="Left" x:Name="progress1" Max="100" Value="{Binding Value, ElementName=range1}" />

<TextBlock FontSize="20">HtmlMeter <Span FontWeight="Bold">&lt;meter/&gt;</Span></TextBlock>
<html:HtmlMeter HorizontalAlignment="Left" x:Name="meter1" Max="100" Value="{Binding Value, ElementName=range1}" />

<TextBlock FontSize="20">HtmlHxText <Span FontWeight="Bold">&lt;h1 /&gt;, &lt;h2 /&gt;, &lt;h3 /&gt;, &lt;h4 /&gt;</Span></TextBlock>
<TextBox x:Name="text" Text="Sample text you can change..." />
<html:HtmlH1Text HorizontalAlignment="Left" x:Name="h1" Text="{Binding Text, ElementName=text}" />
<html:HtmlH2Text HorizontalAlignment="Left" x:Name="h2" Text="{Binding Text, ElementName=text}" />
<html:HtmlH3Text HorizontalAlignment="Left" x:Name="h3" Text="{Binding Text, ElementName=text}" />
<html:HtmlH4Text HorizontalAlignment="Left" x:Name="h4" Text="{Binding Text, ElementName=text}" />

<TextBlock FontSize="20">HtmlSelect / HtmlOption <Span FontWeight="Bold">&lt;select /&gt;, &lt;option /&gt;</Span></TextBlock>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<html:HtmlSelect x:Name="select1">
<html:HtmlOption Value="o1">Option 1</html:HtmlOption>
<html:HtmlOption Value="o2">Option 2</html:HtmlOption>
<html:HtmlOption Value="o3">Option 3</html:HtmlOption>
</html:HtmlSelect>
<TextBlock Text="{Binding SelectedIndex, ElementName=select1}"/>
</StackPanel>
</StackPanel>
</ScrollViewer>
</Page>
159 changes: 159 additions & 0 deletions UI/HtmlControls/HtmlControls/HtmlH1Text.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Uno.Extensions;
using Uno.UI.Runtime.WebAssembly;

namespace HtmlControls
{
[HtmlElement("h1")]
public partial class HtmlH1Text : FrameworkElement
{
public HtmlH1Text()
{
// Set a background to ensure pointer events are allowed
Background = new SolidColorBrush(Colors.Transparent);

// Avoid flicking while we're measuring the element
this.SetCssStyle("overflow", "hidden");
}

public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text", typeof(string), typeof(HtmlH1Text), new PropertyMetadata("", propertyChangedCallback: OnTextChanged));

public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

private static void OnTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
if (o is HtmlH1Text element && args.NewValue is string text)
{
element.SetHtmlContent(text);
element.InvalidateMeasure();
}
}

protected override Size MeasureOverride(Size availableSize)
{
// Delegate measurement to Html <progress> element
return this.MeasureHtmlView(availableSize, false);
}
}

[HtmlElement("h2")]
public partial class HtmlH2Text : FrameworkElement
{
public HtmlH2Text()
{
// Set a background to ensure pointer events are allowed
Background = new SolidColorBrush(Colors.Transparent);

// Avoid flicking while we're measuring the element
this.SetCssStyle("overflow", "hidden");
}

public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text", typeof(string), typeof(HtmlH2Text), new PropertyMetadata("", propertyChangedCallback: OnTextChanged));

public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

private static void OnTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
if (o is HtmlH2Text element && args.NewValue is string text)
{
element.SetHtmlContent(text);
element.InvalidateMeasure();
}
}

protected override Size MeasureOverride(Size availableSize)
{
// Delegate measurement to Html <progress> element
return this.MeasureHtmlView(availableSize, false);
}
}

[HtmlElement("h3")]
public partial class HtmlH3Text : FrameworkElement
{
public HtmlH3Text()
{
// Set a background to ensure pointer events are allowed
Background = new SolidColorBrush(Colors.Transparent);

// Avoid flicking while we're measuring the element
this.SetCssStyle("overflow", "hidden");
}

public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text", typeof(string), typeof(HtmlH3Text), new PropertyMetadata("", propertyChangedCallback: OnTextChanged));

public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

private static void OnTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
if (o is HtmlH3Text element && args.NewValue is string text)
{
element.SetHtmlContent(text);
element.InvalidateMeasure();
}
}

protected override Size MeasureOverride(Size availableSize)
{
// Delegate measurement to Html <progress> element
return this.MeasureHtmlView(availableSize, false);
}
}

[HtmlElement("h4")]
public partial class HtmlH4Text : FrameworkElement
{
public HtmlH4Text()
{
// Set a background to ensure pointer events are allowed
Background = new SolidColorBrush(Colors.Transparent);

// Avoid flicking while we're measuring the element
this.SetCssStyle("overflow", "hidden");
}

public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text", typeof(string), typeof(HtmlH4Text), new PropertyMetadata("", propertyChangedCallback: OnTextChanged));

public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

private static void OnTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
if (o is HtmlH4Text element && args.NewValue is string text)
{
element.SetHtmlContent(text);
element.InvalidateMeasure();
}
}

protected override Size MeasureOverride(Size availableSize)
{
// Delegate measurement to Html <progress> element
return this.MeasureHtmlView(availableSize, false);
}
}


}
79 changes: 79 additions & 0 deletions UI/HtmlControls/HtmlControls/HtmlMeter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Uno.Extensions;
using Uno.UI.Runtime.WebAssembly;

namespace HtmlControls
{
[HtmlElement("meter")]
public partial class HtmlMeter : FrameworkElement
{
public HtmlMeter()
{
// Set a background to ensure pointer events are allowed
Background = new SolidColorBrush(Colors.Transparent);
}

public static readonly DependencyProperty MinProperty = DependencyProperty.Register(
"Min", typeof(double), typeof(HtmlMeter), new PropertyMetadata(0d, propertyChangedCallback: OnMinChanged));

public double Min
{
get => (double)GetValue(MinProperty);
set => SetValue(MinProperty, value);
}

private static void OnMinChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
if (o is HtmlMeter meter && args.NewValue is double min)
{
meter.SetAttribute("min", min.ToStringInvariant());
}
}

public static readonly DependencyProperty MaxProperty = DependencyProperty.Register(
"Max", typeof(double), typeof(HtmlMeter), new PropertyMetadata(1.0d, propertyChangedCallback: OnMaxChanged));

public double Max
{
get => (double)GetValue(MaxProperty);
set => SetValue(MaxProperty, value);
}

private static void OnMaxChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
if (o is HtmlMeter meter && args.NewValue is double max)
{
meter.SetAttribute("max", max.ToStringInvariant());
}
}

public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
"Value", typeof(double), typeof(HtmlMeter), new PropertyMetadata(default(double), propertyChangedCallback: OnValueChanged));

public double Value
{
get => (double)GetValue(ValueProperty);
set => SetValue(ValueProperty, value);
}

private static void OnValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
if (o is HtmlMeter meter && args.NewValue is double value)
{
meter.SetAttribute("value", value.ToStringInvariant());
}
}

protected override Size MeasureOverride(Size availableSize)
{
// Delegate measurement to Html <meter> element
return this.MeasureHtmlView(availableSize, false);
}
}
}
52 changes: 52 additions & 0 deletions UI/HtmlControls/HtmlControls/HtmlOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Markup;
using Uno.UI.Runtime.WebAssembly;

namespace HtmlControls
{
[HtmlElement("option")]
[ContentProperty(Name = nameof(Content))]
public partial class HtmlOption : UIElement
{
public static DependencyProperty ContentProperty { get; } = DependencyProperty.Register(
"ContentProperty", typeof(string), typeof(HtmlOption), new PropertyMetadata(null, OnContentChanged));

public string Content
{
get => (string)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}

private static void OnContentChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
if (o is HtmlOption option)
{
if (args.NewValue is string str)
{
option.ClearChildren();
option.SetHtmlContent(str);
}
}
}

public static DependencyProperty ValueProperty { get; } = DependencyProperty.Register(
"ValueProperty", typeof(string), typeof(HtmlOption), new PropertyMetadata(null, OnValueChanged));

public string Value
{
get => (string)GetValue(ValueProperty);
set => SetValue(ValueProperty, value);
}

private static void OnValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
if (o is HtmlOption option)
{
if (args.NewValue is string str)
{
option.SetAttribute("value", str);
}
}
}
}
}

0 comments on commit 2a74183

Please sign in to comment.