コード例 #1
0
        public void AddClass_ToString_ReturnsTagWithClassAtribute()
        {
            Div d = new Div();
            d.AddClass("classname");

            string html = d.ToString();
            string expected = "<div class=\"classname\"></div>";

            Assert.AreEqual(expected, html);
        }
コード例 #2
0
        public void AddClassAddAttribute_ToString_TagWithClassesAndAttributes()
        {
            Div d = new Div();
            d.AddClass("one");
            d.AddAttribute("first", "val1");
            string html = d.ToString();

            string expected = "<div class=\"one\" first=\"val1\"></div>";
            Assert.AreEqual(expected, html);
        }
コード例 #3
0
        protected static Element ContainerRender(AdaptiveContainer container, ElementAdaptiveRenderContext context)
        {
            var uiContainer = new Div()
                              .AddClass($"ac-{container.Type.Replace(".", "").ToLower()}");

            AddContainerElements(uiContainer, container.Items, null, context);

            if (context.Config.SupportsInteractivity && container.SelectAction != null)
            {
                uiContainer.AddClass("ac-selectable");
                AddActionAttributes(container.SelectAction, uiContainer, context);
            }

            return(uiContainer);
        }
コード例 #4
0
ファイル: Field.cs プロジェクト: tessin/tessin-bladerunner
        public Field(string label, Control input, string description = "", Func <Control, object> helper = null, bool required = false)
        {
            this.Style = "width:-webkit-fill-available;";

            if (input is not DateBox && input is not SearchBox && input is not FileBox)
            {
                input.HtmlElement.SetAttribute("required", "required");
            }

            var dcHelper = new DumpContainer();

            Span _description = null;

            if (!string.IsNullOrEmpty(description))
            {
                _description = new Span("");
                _description.HtmlElement.SetAttribute("title", description);
                _description.SetClass("field--header-description");
            }

            Span _label = new Span(label + (required ? "*" : ""));

            _label.SetClass("field--header-label");

            var divHeader = new Div((new Control[] { _label, _description, dcHelper }).Where(e => e != null).ToArray());

            divHeader.SetClass("field--header");

            if (helper != null)
            {
                input.OnUpdate(() =>
                {
                    dcHelper.Content = helper(input);
                });
                dcHelper.Content = helper(input);
            }

            _divError = new Div();
            _divError.SetClass("field--error");

            var divContainer = new Div(input, divHeader, _divError);

            divContainer.AddClass("field");

            this.Content = divContainer;
        }
コード例 #5
0
        protected static Element ImageRender(AdaptiveImage image, ElementAdaptiveRenderContext context)
        {
            var uiDiv = new Div()
                        .AddClass($"ac-{image.Type.Replace(".", "").ToLower()}")
                        .Style("display", "block")
                        .Style("box-sizing", "border-box");

            switch (image.Size)
            {
            case AdaptiveImageSize.Auto:
                uiDiv = uiDiv.Style("max-width", $"100%");
                break;

            case AdaptiveImageSize.Small:
                uiDiv = uiDiv.Style("max-width", $"{context.Config.ImageSizes.Small}px");
                break;

            case AdaptiveImageSize.Medium:
                uiDiv = uiDiv.Style("max-width", $"{context.Config.ImageSizes.Medium}px");
                break;

            case AdaptiveImageSize.Large:
                uiDiv = uiDiv.Style("max-width", $"{context.Config.ImageSizes.Large}px");
                break;

            case AdaptiveImageSize.Stretch:
                uiDiv = uiDiv.Style("width", $"100%");
                break;
            }

            var uiImage = new Image()
                          .Style("width", "100%")
                          .SetAttr("alt", image.AltText ?? "card image")
                          .SetAttr("src", image.Url.ToString());

            switch (image.Style)
            {
            case AdaptiveImageStyle.Default:
                break;

            case AdaptiveImageStyle.Person:
                uiImage = uiImage.Style("background-position", "50% 50%")
                          .Style("border-radius", "50%")
                          .Style("background-repeat", "no-repeat");
                break;
            }


            switch (image.HorizontalAlignment)
            {
            case AdaptiveHorizontalAlignment.Left:
                uiDiv = uiDiv.Style("overflow", "hidden")
                        .Style("display", "block");
                break;

            case AdaptiveHorizontalAlignment.Center:
                uiDiv = uiDiv.Style("overflow", "hidden")
                        .Style("margin-right", "auto")
                        .Style("margin-left", "auto")
                        .Style("display", "block");
                break;

            case AdaptiveHorizontalAlignment.Right:
                uiDiv = uiDiv.Style("overflow", "hidden")
                        .Style("margin-left", "auto")
                        .Style("display", "block");
                break;
            }
            uiDiv.AppendChild(uiImage);

            if (context.Config.SupportsInteractivity && image.SelectAction != null)
            {
                uiDiv.AddClass("ac-selectable");
                AddActionAttributes(image.SelectAction, uiDiv, context);
            }
            return(uiDiv);
        }
コード例 #6
0
        protected static Element ColumnSetRender(AdaptiveColumnSet columnSet, ElementAdaptiveRenderContext context)
        {
            var uiColumnSet = new Div()
                              .AddClass($"ac-{columnSet.Type.Replace(".", "").ToLower()}")
                              .Style("overflow", "hidden")
                              .Style("display", "flex");

            // selectAction
            if (context.Config.SupportsInteractivity && columnSet.SelectAction != null)
            {
                uiColumnSet.AddClass("ac-selectable");
                AddActionAttributes(columnSet.SelectAction, uiColumnSet, context);
            }

            var max = Math.Max(1.0, columnSet.Columns.Select(col =>
            {
                if (col.Width != null && double.TryParse(col.Width, out double widthVal))
                {
                    return(widthVal);
                }
#pragma warning disable CS0618 // Type or member is obsolete
                if (double.TryParse(col.Size ?? "0", out double val))
#pragma warning restore CS0618 // Type or member is obsolete
                {
                    return(val);
                }
                return(0);
            }).Sum());

            foreach (var column in columnSet.Columns)
            {
                var uiColumn = context.Render(column);

                // Add horizontal Seperator
                if (uiColumnSet.Children.Any() && (column.Separator || column.Spacing != AdaptiveSpacing.None))
                {
                    SeparatorConfig sep = context.Config.Separator;

                    int spacing       = context.Config.GetSpacing(column.Spacing) / 2;
                    int lineThickness = column.Separator ? sep.LineThickness : 0;

                    if (sep != null)
                    {
                        uiColumnSet.AppendChild(new Div()
                                                .AddClass($"ac-columnseparator")
                                                .Style("flex", "0 0 auto")
                                                .Style("padding-left", $"{spacing}px")
                                                .Style("margin-left", $"{spacing}px")
                                                .Style("border-left-color", $"{context.GetRGBColor(sep.LineColor)}")
                                                .Style("border-left-width", $"{lineThickness}px")
                                                .Style("border-left-style", $"solid"));
                    }
                }

                // do some sizing magic
                var width = column.Width?.ToLower();
                if (string.IsNullOrEmpty(width))
#pragma warning disable CS0618 // Type or member is obsolete
                {
                    width = column.Size?.ToLower();
                }
#pragma warning restore CS0618 // Type or member is obsolete
                if (width == null || width == AdaptiveColumnWidth.Stretch.ToLower())
                {
                    uiColumn = uiColumn.Style("flex", "1 1 auto");
                }
                else if (width == AdaptiveColumnWidth.Auto.ToLower())
                {
                    uiColumn = uiColumn.Style("flex", "0 1 auto");
                }
                else
                {
                    double val;
                    if (double.TryParse(width, out val))
                    {
                        var percent = Convert.ToInt32(100 * (val / max));
                        uiColumn = uiColumn.Style("flex", $"1 1 {percent}%");
                    }
                    else
                    {
                        uiColumn = uiColumn.Style("flex", "0 0 auto");
                    }
                }

                uiColumnSet.AppendChild(uiColumn);
            }

            return(uiColumnSet);
        }
コード例 #7
0
        public void AddTwoClasses_ToString_RetuwnsTagWithTwoClasses()
        {
            Div d = new Div();
            d.AddClass("one");
            d.AddClass("two");

            string html = d.ToString();
            string expected = "<div class=\"one two\"></div>";
            Assert.AreEqual(expected, html);
        }