Beispiel #1
0
        // https://github.com/jsakamoto/Toolbelt.Blazor.HeadElement/blob/master/Components/Title.razor
        // TODO: this is unsupported. If something goes wrong this is the issue
        public static string AsString(this RenderFragment renderFragment)
        {
            var renderTreeBuilder = new RenderTreeBuilder();

            renderFragment.Invoke(renderTreeBuilder);

            var frames  = renderTreeBuilder.GetFrames();
            var content = new StringBuilder();

#pragma warning disable BL0006 // Do not use RenderTree types

            foreach (var frame in frames.Array)
            {
                switch (frame.FrameType)
                {
                case RenderTreeFrameType.Text:
                    content.Append(frame.TextContent);
                    break;

                case RenderTreeFrameType.Markup:
                    content.Append(frame.MarkupContent);
                    break;

                default:
                    break;
                }
            }

#pragma warning restore BL0006 // Do not use RenderTree types

            return(content.ToString());
        }
Beispiel #2
0
        public void Add <T>(RenderFragment css)
        {
            if (!_styles.ContainsKey(typeof(T)))
            {
                var renderTreeBuilder = new RenderTreeBuilder();
                css.Invoke(renderTreeBuilder);
                var frames  = renderTreeBuilder.GetFrames();
                var content = frames.Array.FirstOrDefault().TextContent;

                if (content == null)
                {
                    throw new ArgumentException("RenderFragment can only contain CSS");
                }

                content = Regex.Replace(content, @"\s+", " ");

                var prefix   = $"#comp{typeof(T).FullName.GetHashCode()}";
                var sections = content.Split('}').Where(x => !string.IsNullOrWhiteSpace(x));
                var prefixed = string.Join("} ", sections.Select(x => prefix + x)) + "}";

                _styles.Add(typeof(T), prefixed);
                AddedCallback?.Invoke();
            }
        }
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            RenderFragment applicableRenderFragment = this.CurrentParticipantInfo.IsFacilitator ? this.Facilitator : this.Participant;

            applicableRenderFragment.Invoke(builder);
        }
Beispiel #4
0
 public async Task HandleSelectAsync(T item, RenderFragment <T> contentFragment)
 {
     tip  = contentFragment.Invoke(item);
     show = false;
     await OnSelected.InvokeAsync(item);
 }