Exemplo n.º 1
0
        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("type", out var t))
            {
                Type = t?.ToString();
            }

            if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("placeholder", out var ph))
            {
                PlaceHolder = ph?.ToString();
            }
            if (string.IsNullOrEmpty(PlaceHolder) && FieldIdentifier.HasValue)
            {
                PlaceHolder = FieldIdentifier.Value.GetPlaceHolder();
            }

            // 设置 Number 类型
            if (typeof(TValue).IsNumber())
            {
                Type = "number";
                if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("step", out var step))
                {
                    Step = step?.ToString();
                }
                else
                {
                    Step = "any";
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            PlaceHolder ??= Localizer[nameof(PlaceHolder)];

            if (OnSearchTextChanged == null)
            {
                OnSearchTextChanged = text => Items.Where(i => i.Text.Contains(text, StringComparison.OrdinalIgnoreCase));
            }

            // 内置对枚举类型的支持
            var t = typeof(TValue);

            if (!Items.Any() && t.IsEnum())
            {
                var item = "";

                // 如果可为空枚举增加 请选择 ...
                if (Nullable.GetUnderlyingType(t) != null)
                {
                    // 优先查找 placeholder 字样 如果未设置使用资源文件中
                    if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("placeholder", out var pl))
                    {
                        item = pl.ToString();
                    }
                    else
                    {
                        item = Localizer["PlaceHolder"].Value;
                    }
                }

                Items = typeof(TValue).ToSelectList(string.IsNullOrEmpty(item) ? null : new SelectedItem("", item));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (AdditionalAttributes == null)
            {
                AdditionalAttributes = new Dictionary <string, object>();
            }

            if (!AdditionalAttributes.TryGetValue("type", out var _))
            {
                AdditionalAttributes["type"] = "button";
            }

            var onClick = OnClick;

            OnClick = EventCallback.Factory.Create <MouseEventArgs>(this, async e =>
            {
                if (!IsDisabled)
                {
                    if (OnClickWithoutRender != null)
                    {
                        await OnClickWithoutRender.Invoke();
                    }
                    if (onClick.HasDelegate)
                    {
                        await onClick.InvokeAsync(e);
                    }
                }
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// OnParametersSet 方法
        /// </summary>
        protected override void OnParametersSet()
        {
            base.OnParametersSet();

            if (NullableUnderlyingType != null)
            {
                if (string.IsNullOrEmpty(PlaceHolder))
                {
                    // 设置 placeholder
                    if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("placeholder", out var pl))
                    {
                        PlaceHolder = pl?.ToString();
                        AdditionalAttributes.Remove("placeholder");
                    }
                }
                PlaceHolder ??= Localizer[nameof(PlaceHolder)];
            }

            // 内置对枚举类型的支持
            var t = NullableUnderlyingType ?? typeof(TValue);

            if (!Items.Any() && t.IsEnum())
            {
                var item = NullableUnderlyingType == null ? "" : PlaceHolder;
                Items = typeof(TValue).ToSelectList(string.IsNullOrEmpty(item) ? null : new SelectedItem("", item));
            }
        }
Exemplo n.º 5
0
        private string GetCssClass(string fieldClass)
        {
            if (AdditionalAttributes != null &&
                AdditionalAttributes.TryGetValue("class", out var @class) &&
                !string.IsNullOrEmpty(Convert.ToString(@class, CultureInfo.InvariantCulture)))
            {
                return($"{@class} {fieldClass}");
            }

            return(fieldClass);
        }
Exemplo n.º 6
0
 private string GetBaseClassAttributes()
 {
     if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("class", out var clsAttributeObj))
     {
         var classAttributes = Convert.ToString(clsAttributeObj, CultureInfo.InvariantCulture);
         if (!string.IsNullOrWhiteSpace(classAttributes))
         {
             return($"input-endorsement {classAttributes}");
         }
     }
     return("input-endorsement");
 }
Exemplo n.º 7
0
        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (AdditionalAttributes == null)
            {
                AdditionalAttributes = new Dictionary <string, object>();
            }

            if (!AdditionalAttributes.TryGetValue("type", out var _))
            {
                AdditionalAttributes["type"] = "button";
            }

            ButtonIcon = Icon;

            OnClickButton = EventCallback.Factory.Create <MouseEventArgs>(this, async() =>
            {
                if (IsAsync && ButtonType == ButtonType.Button)
                {
                    IsAsyncLoading = true;
                    ButtonIcon     = LoadingIcon;
                    IsDisabled     = true;
                }
                if (IsAsync)
                {
                    await Task.Run(async() => await InvokeAsync(HandlerClick));
                }
                else
                {
                    await HandlerClick();
                }
                if (IsAsync && ButtonType == ButtonType.Button)
                {
                    ButtonIcon     = Icon;
                    IsDisabled     = false;
                    IsAsyncLoading = false;
                }
            });

            async Task HandlerClick()
            {
                if (OnClickWithoutRender != null)
                {
                    await OnClickWithoutRender.Invoke();
                }
                if (OnClick.HasDelegate)
                {
                    await OnClick.InvokeAsync();
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("placeholder", out var ph))
            {
                PlaceHolder = ph?.ToString();
            }
            if (string.IsNullOrEmpty(PlaceHolder) && FieldIdentifier.HasValue)
            {
                PlaceHolder = FieldIdentifier.Value.GetPlaceHolder();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            // TODO: 此处应该检查 html5 type 类型检查
            if (AdditionalAttributes != null)
            {
                if (!AdditionalAttributes.TryGetValue("type", out var _))
                {
                    AdditionalAttributes.Add("type", IsPassword ? "password" : "text");
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("type", out var t))
            {
                Type = t.ToString() !;
            }

            // 设置 Number 类型
            if (typeof(TValue).IsNumber())
            {
                Type = "number";
            }
        }
Exemplo n.º 11
0
        /// <inheritdoc />
        protected override void OnParametersSet()
        {
            // Update computed state
            var href = (string?)null;

            if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("href", out var obj))
            {
                href = Convert.ToString(obj);
            }

            _hrefAbsolute = href == null ? null : NavigationManger.ToAbsoluteUri(href).AbsoluteUri;
            _isActive     = ShouldMatch(NavigationManger.Uri);

            UpdateCssClass();
        }
Exemplo n.º 12
0
    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        if (string.IsNullOrEmpty(PlaceHolder) && FieldIdentifier.HasValue)
        {
            PlaceHolder = FieldIdentifier.Value.GetPlaceHolder();
        }

        if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("type", out var t))
        {
            var type = t.ToString();
            if (!string.IsNullOrEmpty(type))
            {
                Type = type;
            }
        }
    }
Exemplo n.º 13
0
        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            // 初始化 Tooltip 组件
            if (Tooltip != null)
            {
                if (AdditionalAttributes == null)
                {
                    AdditionalAttributes = new Dictionary <string, object>();
                }
                AdditionalAttributes["data-placement"] = Tooltip.Placement.ToDescriptionString();

                if (!AdditionalAttributes.TryGetValue("data-trigger", out var _) && !string.IsNullOrEmpty(Tooltip.Trigger))
                {
                    AdditionalAttributes["data-trigger"] = Tooltip.Trigger;
                }
            }
        }
Exemplo n.º 14
0
        /// <inheritdoc />
        protected override void OnParametersSet()
        {
            // Update computed state
            var href = (string)null;

            if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("href", out var obj))
            {
                href = Convert.ToString(obj);
            }

            _hrefAbsolute = href == null ? null : UriHelper.ToAbsoluteUri(href).AbsoluteUri;
            _isActive     = ShouldMatch(UriHelper.GetAbsoluteUri());

            _class = (string)null;
            if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("class", out obj))
            {
                _class = Convert.ToString(obj);
            }

            UpdateCssClass();
        }
Exemplo n.º 15
0
        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (AdditionalAttributes == null)
            {
                AdditionalAttributes = new Dictionary <string, object>();
            }

            if (!AdditionalAttributes.TryGetValue("type", out var _))
            {
                // 设置 Number 类型
                if (typeof(TValue).IsNumber())
                {
                    AdditionalAttributes.Add("type", "number");
                }
                else
                {
                    AdditionalAttributes.Add("type", IsPassword ? "password" : "text");
                }
            }
        }
Exemplo n.º 16
0
        /// <inheritdoc />
        protected override void BuildInput(RenderTreeBuilder builder, int sequence)
        {
            builder.OpenElement(0, "div");
            builder.AddAttribute(1, "class", "form-check");
            {
                builder.OpenElement(0, "input");
                builder.AddMultipleAttributes(1, AdditionalAttributes);
                builder.AddAttribute(2, "type", "checkbox");
                builder.AddAttribute(3, "class", $"form-check-input {CssClass}");
                builder.AddAttribute(4, "checked", BindConverter.FormatValue(CurrentValue));
                builder.AddAttribute(5, "onchange", EventCallback.Factory.CreateBinder <bool>(this, __value => CurrentValue = __value, CurrentValue));
                builder.CloseElement();

                object placeholder = null;
                AdditionalAttributes?.TryGetValue("placeholder", out placeholder);

                builder.OpenElement(0, "label");
                builder.AddAttribute(1, "class", "form-check-label");
                builder.AddContent(0, placeholder ?? Label);
                builder.CloseElement();
            }
            builder.CloseElement();
        }
Exemplo n.º 17
0
        /// <summary>
        /// inherited
        /// Builds the render tree for the component
        /// </summary>
        /// <param name="builder"></param>
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            var css      = string.Empty;
            var viewData = new ViewData(ViewType, ViewParameters);

            if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("class", out var obj))
            {
                css = Convert.ToString(obj, CultureInfo.InvariantCulture);
            }
            if (this.IsActive)
            {
                css = $"{css} active";
            }
            this.UsedAttributes.Add("@onclick");
            this.UsedAttributes.Add("onclick");
            this.ClearDuplicateAttributes();
            builder.OpenElement(0, "a");
            builder.AddAttribute(1, "class", css);
            builder.AddMultipleAttributes(2, AdditionalAttributes);
            //builder.AddAttribute(3, "onclick", Microsoft.AspNetCore.Components.EventCallback.Factory.Create<Microsoft.AspNetCore.Components.Web.MouseEventArgs>(this, e => this.ViewManager.LoadViewAsync(viewData)));
            builder.AddAttribute(3, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, e => this.ViewManager.LoadViewAsync(viewData)));
            builder.AddContent(4, ChildContent);
            builder.CloseElement();
        }
Exemplo n.º 18
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (builder != null)
            {
                base.BuildRenderTree(builder);

                string container = "input";

                if (AddOnBefore != null || AddOnAfter != null)
                {
                    container        = "groupWrapper";
                    _hasAffixWrapper = true;
                    builder.OpenElement(1, "span");
                    builder.AddAttribute(2, "class", GroupWrapperClass);
                    builder.AddAttribute(3, "style", Style);
                    builder.OpenElement(4, "span");
                    builder.AddAttribute(5, "class", $"{PrefixCls}-wrapper {PrefixCls}-group");
                }

                if (AddOnBefore != null)
                {
                    _hasAffixWrapper = true;
                    // addOnBefore
                    builder.OpenElement(11, "span");
                    builder.AddAttribute(12, "class", $"{PrefixCls}-group-addon");
                    builder.AddContent(13, AddOnBefore);
                    builder.CloseElement();
                }

                if (Prefix != null || Suffix != null)
                {
                    _hasAffixWrapper = true;
                    builder.OpenElement(21, "span");
                    builder.AddAttribute(22, "class", AffixWrapperClass);
                    if (container == "input")
                    {
                        container = "affixWrapper";
                        builder.AddAttribute(23, "style", Style);
                    }
                    if (WrapperRefBack != null)
                    {
                        builder.AddElementReferenceCapture(24, r => WrapperRefBack.Current = r);
                    }
                }

                if (Prefix != null)
                {
                    _hasAffixWrapper = true;
                    // prefix
                    builder.OpenElement(31, "span");
                    builder.AddAttribute(32, "class", $"{PrefixCls}-prefix");
                    builder.AddContent(33, Prefix);
                    builder.CloseElement();
                }

                // input
                builder.OpenElement(41, "input");
                builder.AddAttribute(42, "class", ClassMapper.Class);
                if (container == "input")
                {
                    builder.AddAttribute(43, "style", Style);
                }

                bool needsDisabled = Disabled;
                if (Attributes != null)
                {
                    builder.AddMultipleAttributes(44, Attributes);
                    if (!Attributes.TryGetValue("disabled", out object disabledAttribute))
                    {
                        needsDisabled = ((bool?)disabledAttribute ?? needsDisabled) | Disabled;
                    }
                }

                if (AdditionalAttributes != null)
                {
                    builder.AddMultipleAttributes(45, AdditionalAttributes);
                    if (!AdditionalAttributes.TryGetValue("disabled", out object disabledAttribute))
                    {
                        needsDisabled = ((bool?)disabledAttribute ?? needsDisabled) | Disabled;
                    }
                }

                builder.AddAttribute(50, "Id", Id);
                builder.AddAttribute(51, "type", Type);
                builder.AddAttribute(60, "placeholder", Placeholder);
                builder.AddAttribute(61, "value", CurrentValue);
                builder.AddAttribute(62, "disabled", needsDisabled);

                // onchange 和 onblur 事件会导致点击 OnSearch 按钮时不触发 Click 事件,暂时取消这两个事件
                if (!IgnoreOnChangeAndBlur)
                {
                    builder.AddAttribute(70, "onchange", CallbackFactory.Create(this, OnChangeAsync));
                    builder.AddAttribute(71, "onblur", CallbackFactory.Create(this, OnBlurAsync));
                }

                builder.AddAttribute(72, "onkeypress", CallbackFactory.Create(this, OnKeyPressAsync));
                builder.AddAttribute(73, "onkeydown", CallbackFactory.Create(this, OnkeyDownAsync));
                builder.AddAttribute(74, "onkeyup", CallbackFactory.Create(this, OnKeyUpAsync));
                builder.AddAttribute(75, "oninput", CallbackFactory.Create(this, OnInputAsync));
                builder.AddAttribute(76, "onfocus", CallbackFactory.Create(this, OnFocusAsync));
                builder.AddAttribute(77, "onmouseup", CallbackFactory.Create(this, OnMouseUpAsync));
                builder.AddElementReferenceCapture(90, r => Ref = r);
                builder.CloseElement();

                if (Suffix != null)
                {
                    _hasAffixWrapper = true;
                    // suffix
                    builder.OpenElement(91, "span");
                    builder.AddAttribute(92, "class", $"{PrefixCls}-suffix");
                    builder.AddContent(93, Suffix);
                    builder.CloseElement();
                }

                if (Prefix != null || Suffix != null)
                {
                    builder.CloseElement();
                }

                if (AddOnAfter != null)
                {
                    _hasAffixWrapper = true;
                    // addOnAfter
                    builder.OpenElement(100, "span");
                    builder.AddAttribute(101, "class", $"{PrefixCls}-group-addon");
                    builder.AddContent(102, AddOnAfter);
                    builder.CloseElement();
                }

                if (AddOnBefore != null || AddOnAfter != null)
                {
                    builder.CloseElement();
                    builder.CloseElement();
                }
            }
        }