Example #1
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            Member <TS, TM> member = StructureInstance.Structure.GetMember <TM>(ID !);

            ClassSet classes = ClassSet.FromMember(Value, member,
                                                   "Integrant.Rudiment.Component." + nameof(MemberContainer <TS, TM>));

            bool shown = member.IsVisible?.Invoke(Value, member) ?? true;

            //

            int seq = -1;

            builder.OpenElement(++seq, Element ?? "div");

            builder.AddAttribute(++seq, "class", classes.ToString());

            if (!shown)
            {
                builder.AddAttribute(++seq, "hidden", "hidden");
            }

            builder.OpenComponent <CascadingValue <string> >(++seq);
            builder.AddAttribute(++seq, "Name", "Integrant.Rudiment.Member.ID");
            builder.AddAttribute(++seq, "Value", ID);
            builder.AddAttribute(++seq, "IsFixed", true);
            builder.AddAttribute(++seq, "ChildContent", ChildContent);
            builder.CloseComponent();

            builder.CloseElement();
        }
Example #2
0
        public RenderFragment Render
        (
            StructureInstance <TStructure> structure, TStructure value, MemberInstance <TStructure, TID> member
        ) => builder =>
        {
            if (structure.JSRuntime == null)
            {
                throw new ArgumentException(
                          "StructureInstance passed to ComboboxInput does not have a set JSRuntime.",
                          nameof(structure.JSRuntime));
            }

            int seq = -1;

            builder.OpenElement(++seq, "div");

            //

            ClassSet classes = new ClassSet
                               (
                "Integrant.Element.Override.Input",
                "Integrant.Rudiment.Input." + nameof(ComboboxInput <TStructure, TID>)
                               );

            InputBuilder.Required(value, member.Member, classes);
            InputBuilder.Disabled(value, member.Member, classes);

            builder.AddAttribute(++seq, "class", classes.ToString());

            //

            InitCombobox(structure, value, member);

            _combobox !.OnSelect += o => OnInput?.Invoke(value, o != null ? o.Value : default !);
Example #3
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            int seq = -1;

            var rootClasses =
                new ClassSet("Integrant.Element.Component", "Integrant.Element.Component.Modal");

            if (Modal !.Shown)
            {
                rootClasses.Add("Integrant.Element.Component.Modal:Shown");
            }

            // -> Container

            builder.OpenElement(++seq, "div");
            builder.AddAttribute(++seq, "hidden", !Modal !.Shown);
            builder.AddAttribute(++seq, "class", rootClasses.ToString());
            builder.AddAttribute(++seq, "onclick",
                                 EventCallback.Factory.Create <MouseEventArgs>(this, OnBackgroundClick));
            builder.AddElementReferenceCapture(++seq, elemRef => _elemRef = elemRef);

            // - -> Constrainer

            builder.OpenElement(++seq, "div");
            builder.AddAttribute(++seq, "class", "Integrant.Element.Component.Modal.Constrainer");
            builder.AddAttribute(++seq, "style", $"max-width: {Modal.MaxWidth()};");

            // - - -> Content container

            builder.OpenElement(++seq, "div");
            builder.AddAttribute(++seq, "class", "Integrant.Element.Component.Modal.Content");
            builder.AddAttribute(++seq, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, OnContentClick));
            builder.AddEventStopPropagationAttribute(++seq, "onclick", true);

            // - - - -> Close button

            builder.OpenElement(++seq, "span");
            builder.AddAttribute(++seq, "class", "Integrant.Element.Component.Modal.CloseButton");
            builder.AddAttribute(++seq, "onclick",
                                 EventCallback.Factory.Create <MouseEventArgs>(this, OnCloseButtonClick));
            builder.OpenComponent <MaterialIcon>(++seq);
            builder.AddAttribute(++seq, "ID", "close");
            builder.CloseComponent();
            builder.CloseElement();

            // - - - -> Content

            builder.AddContent(++seq, ChildContent);

            //

            builder.CloseElement();

            builder.CloseElement();

            builder.CloseElement();
        }
Example #4
0
        public RenderFragment Render
        (
            StructureInstance <TStructure> structure, TStructure value, MemberInstance <TStructure, TMember> member
        ) => builder =>
        {
            int seq = -1;

            builder.OpenElement(++seq, "div");

            //

            var classes = new ClassSet(
                "Integrant.Element.Override.Input",
                "Integrant.Rudiment.Input." + nameof(NumberInput <TStructure, TMember>)
                );

            bool required = InputBuilder.Required(value, member.Member, classes);
            bool disabled = InputBuilder.Disabled(value, member.Member, classes);

            builder.AddAttribute(++seq, "class", classes.ToString());

            //

            InputBuilder.OpenInnerInput
            (
                builder, ref seq,
                value, member.Member,
                "input", "number",
                "value", member.Member.InputValue.Invoke(value, member.Member),
                required, disabled,
                args => OnChange(value, member.Member, args)
            );

            if (_min != null)
            {
                builder.AddAttribute(++seq, "min", _min.Value);
            }

            if (_max != null)
            {
                builder.AddAttribute(++seq, "max", _max.Value);
            }

            if (_step != null)
            {
                builder.AddAttribute(++seq, "step", _step.Value);
            }

            InputBuilder.CloseInnerInput(builder);

            builder.CloseElement();
        };
Example #5
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            ClassSet classSet = ClassSet.FromMember(Value, _member.Member,
                                                    "Integrant.Rudiment.Component." + nameof(MemberInput <TS, TM>));

            //

            int seq = -1;

            builder.OpenElement(++seq, "div");

            builder.AddAttribute(++seq, "class", classSet.ToString());

            builder.AddContent(++seq, _member.Input !.Render(StructureInstance, Value, _member));

            builder.CloseElement();
        }
Example #6
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (StructureInstance.Structure.Validator == null)
            {
                throw new ArgumentNullException(nameof(StructureInstance.Structure.Validator),
                                                "Structure passed to " + nameof(StructureValidations <TS>) + " component does not have a " +
                                                nameof(StructureGetters.StructureValidations <TS>) + ".");
            }

            ClassSet classes = ClassSet.FromStructure(StructureInstance.Structure, Value,
                                                      "Integrant.Rudiment.Component." + nameof(StructureValidations <TS>));

            bool shown = StructureInstance.Structure.IsVisible?.Invoke(StructureInstance.Structure, Value) ?? true;

            //

            int seq = -1;

            builder.OpenElement(++seq, "div");

            builder.AddAttribute(++seq, "class", classes.ToString());

            if (!shown)
            {
                builder.AddAttribute(++seq, "hidden", "hidden");
            }

            if (StructureInstance.ValidationState.IsValidating)
            {
                ValidationBuilder.RenderValidatingNotice(builder, ref seq);
            }
            else
            {
                List <Validation>?validations = StructureInstance.ValidationState.GetStructureValidations();

                if (validations != null)
                {
                    foreach (Validation validation in validations)
                    {
                        builder.AddContent(++seq, ValidationBuilder.RenderResult(validation));
                    }
                }
            }

            builder.CloseElement();
        }
Example #7
0
        // private readonly Restrictor _restrictor = new Restrictor();

        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            Member <TS, TM> member = StructureInstance.Structure.GetMember <TM>(ID);

            ClassSet classes = ClassSet.FromMember(Value, member,
                                                   "Integrant.Rudiment.Component." + nameof(MemberKey <TS, TM>));

            //

            int seq = -1;

            builder.OpenElement(++seq, "div");

            builder.AddAttribute(++seq, "class", classes.ToString());

            builder.AddContent(++seq, member.Key.Invoke(Value, member));

            builder.CloseElement();
        }
Example #8
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            Member <TS, TM> member = StructureInstance.Structure.GetMember <TM>(ID);

            if (member.Validator == null)
            {
                throw new ArgumentNullException(nameof(member.Validator),
                                                "Member passed to " + nameof(MemberValidations <TS, TM>) + " component does not have a " +
                                                nameof(MemberGetters.MemberValidations <TS, TM>) + ".");
            }

            ClassSet classes = ClassSet.FromMember(Value, member,
                                                   "Integrant.Rudiment.Component." + nameof(MemberValidations <TS, TM>));

            //

            int seq = -1;

            builder.OpenElement(++seq, "div");

            builder.AddAttribute(++seq, "class", classes.ToString());

            if (StructureInstance.ValidationState.IsValidating)
            {
                ValidationBuilder.RenderValidatingNotice(builder, ref seq);
            }
            else
            {
                List <Validation>?validations = StructureInstance.ValidationState.GetMemberValidations(ID);

                if (validations != null)
                {
                    foreach (Validation validation in validations)
                    {
                        builder.AddContent(++seq, ValidationBuilder.RenderResult(validation));
                    }
                }
            }

            builder.CloseElement();
        }
Example #9
0
        protected internal string Class(bool initial, string[]?additional = null)
        {
            ClassSet c = ConstantClasses.Clone();

            if (additional != null)
            {
                c.AddRange(additional);
            }

            if (Spec.IsDisabled?.Invoke() == true)
            {
                c.Add("Integrant.Element.Bit:Disabled");
            }

            if (Spec.Classes != null)
            {
                c.AddRange(Spec.Classes.Invoke());
            }

            return(c.ToString());
        }
Example #10
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            ClassSet classes = ClassSet.FromStructure(StructureInstance.Structure, Value,
                                                      "Integrant.Rudiment.Component." + nameof(StructureContainer <TS>));

            bool shown = StructureInstance.Structure.IsVisible?.Invoke(StructureInstance.Structure, Value) ?? true;

            //

            int seq = -1;

            builder.OpenComponent <CascadingValue <StructureInstance <TS> > >(++seq);
            builder.AddAttribute(++seq, "Name", "Integrant.Rudiment.StructureInstance");
            builder.AddAttribute(++seq, "Value", StructureInstance);
            builder.AddAttribute(++seq, "IsFixed", true);
            builder.AddAttribute(++seq, "ChildContent", new RenderFragment(builder2 =>
            {
                builder2.OpenComponent <CascadingValue <TS> >(++seq);
                builder2.AddAttribute(++seq, "Name", "Integrant.Rudiment.Value");
                builder2.AddAttribute(++seq, "Value", Value);
                builder2.AddAttribute(++seq, "IsFixed", false);
                builder2.AddAttribute(++seq, "ChildContent", new RenderFragment(builder3 =>
                {
                    builder3.OpenElement(++seq, "div");
                    builder3.AddAttribute(++seq, "class", classes.ToString());

                    if (!shown)
                    {
                        builder3.AddAttribute(++seq, "hidden", "hidden");
                    }

                    builder3.AddContent(++seq, ChildContent);

                    builder3.CloseElement();
                }));

                builder2.CloseComponent();
            }));
            builder.CloseComponent();
        }
Example #11
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            Member <TS, TM> member = StructureInstance.Structure.GetMember <TM>(ID);

            ClassSet classes = ClassSet.FromMember(Value, member,
                                                   "Integrant.Rudiment.Component." + nameof(MemberValue <TS, TM>));

            //

            int seq = -1;

            builder.OpenElement(++seq, "div");

            builder.AddAttribute(++seq, "class", classes.ToString());

            object?v = member.DisplayValue.Invoke(Value, member);

            builder.AddContent(++seq, member.ConsiderDefaultNull
                ? Equals(v, default(TM)) ? "" : v
                : v);

            builder.CloseElement();
        }
Example #12
0
        public RenderFragment Render
        (
            StructureInstance <TStructure> structure, TStructure value, MemberInstance <TStructure, bool> member
        ) => builder =>
        {
            int seq = -1;

            builder.OpenElement(++seq, "div");

            //

            ClassSet classes = new ClassSet
                               (
                "Integrant.Element.Override.Input",
                "Integrant.Rudiment.Input." + nameof(CheckboxInput <TStructure>)
                               );

            bool required = InputBuilder.Required(value, member.Member, classes);
            bool disabled = InputBuilder.Disabled(value, member.Member, classes);

            builder.AddAttribute(++seq, "class", classes.ToString());

            //

            _checkbox ??= new Checkbox
            (
                onToggle: c => OnInput?.Invoke(value, c),
                isChecked: () => member.Member.InputValue.Invoke(value, member.Member) is bool b && b,
                isDisabled: () => member.Member.InputIsDisabled?.Invoke(value, member.Member) == true
            );

            builder.AddContent(++seq, _checkbox.Render());

            //

            builder.CloseElement();
        };
Example #13
0
        public RenderFragment Render
        (
            StructureInstance <TStructure> structure, TStructure value, MemberInstance <TStructure, DateTime> member
        ) => builder =>
        {
            int seq = -1;

            builder.OpenElement(++seq, "div");

            var classes = new ClassSet(
                "Integrant.Element.Override.Input",
                "Integrant.Element.Override.Input:Composite",
                "Integrant.Rudiment.Input." + nameof(DateTimeInput <TStructure>)
                );

            builder.AddAttribute(++seq, "class", classes.ToString());

            //

            builder.AddContent(++seq, _dateInput.Render(structure, value, member));
            builder.AddContent(++seq, _timeInput.Render(structure, value, member));

            builder.CloseElement();
        };
Example #14
0
        public RenderFragment Render
        (
            StructureInstance <TStructure> structure, TStructure value, MemberInstance <TStructure, DateTime> member
        ) => builder =>
        {
            int seq = -1;

            builder.OpenElement(++seq, "div");

            //

            var classes = new ClassSet(
                "Integrant.Element.Override.Input",
                "Integrant.Rudiment.Input." + nameof(DateInput <TStructure>)
                );

            bool required = InputBuilder.Required(value, member.Member, classes);
            bool disabled = InputBuilder.Disabled(value, member.Member, classes);

            builder.AddAttribute(++seq, "class", classes.ToString());

            //

            InputBuilder.OpenInnerInput
            (
                builder, ref seq,
                value, member.Member,
                "input", "date",
                "value", TransformValue(structure.Structure, value, member.Member),
                required, disabled,
                args => OnChange(value, args)
            );
            InputBuilder.CloseInnerInput(builder);

            builder.CloseElement();
        };
Example #15
0
        public RenderFragment Render
        (
            StructureInstance <TStructure> structure, TStructure value, MemberInstance <TStructure, string> member
        ) => builder =>
        {
            int seq = -1;

            builder.OpenElement(++seq, "div");

            //

            ClassSet classes = new ClassSet
                               (
                "Integrant.Element.Override.Input",
                "Integrant.Rudiment.Input." + nameof(StringInput <TStructure>)
                               );

            if (TextArea)
            {
                classes.Add("Integrant.Rudiment.Input:TextArea");
            }
            if (Monospace)
            {
                classes.Add("Integrant.Rudiment.Input:Monospace");
            }

            bool required = InputBuilder.Required(value, member.Member, classes);
            bool disabled = InputBuilder.Disabled(value, member.Member, classes);

            builder.AddAttribute(++seq, "class", classes.ToString());

            //

            if (!TextArea)
            {
                InputBuilder.OpenInnerInput
                (
                    builder, ref seq,
                    value, member.Member,
                    "input", "text",
                    "value", member.Member.InputValue.Invoke(value, member.Member),
                    required, disabled,
                    args => OnChange(value, args)
                );
                InputBuilder.CloseInnerInput(builder);
            }
            else
            {
                InputBuilder.OpenInnerInput
                (
                    builder, ref seq,
                    value, member.Member,
                    "textarea", null,
                    "value", member.Member.InputValue.Invoke(value, member.Member),
                    required, disabled,
                    args => OnChange(value, args)
                );

                if (TextAreaCols != null)
                {
                    builder.AddAttribute(++seq, "cols", TextAreaCols.Invoke(value, member.Member, this));
                }
                if (TextAreaRows != null)
                {
                    builder.AddAttribute(++seq, "rows", TextAreaRows.Invoke(value, member.Member, this));
                }

                InputBuilder.CloseInnerInput(builder);
            }

            builder.CloseElement();
        };
Example #16
0
        public RenderFragment Render
        (
            StructureInstance <TStructure> structure, TStructure value, MemberInstance <TStructure, TID> member
        ) => builder =>
        {
            int seq = -1;

            builder.OpenElement(++seq, "div");

            //

            ClassSet classes = new ClassSet
                               (
                "Integrant.Element.Override.Input",
                "Integrant.Rudiment.Input." + nameof(SelectInput <TStructure, TID>)
                               );

            bool required = InputBuilder.Required(value, member.Member, classes);
            bool disabled = InputBuilder.Disabled(value, member.Member, classes);

            builder.AddAttribute(++seq, "class", classes.ToString());

            if (member.Member.InputPlaceholder != null)
            {
                builder.AddAttribute(++seq, "placeholder",
                                     member.Member.InputPlaceholder.Invoke(value, member.Member));
            }

            //

            List <IOption <TID> > options = _options.Invoke(value, member.Member).ToList();
            object?v = member.Member.InputValue.Invoke(value, member.Member);

            int?selectedIndex = null;

            if (v != null)
            {
                selectedIndex = options.FindIndex(q => q.Value.Equals(v));
                if (selectedIndex == -1)
                {
                    selectedIndex = null;
                }
                // Console.WriteLine($"Selected index: {selectedIndex}");
            }

            InputBuilder.OpenInnerInput
            (
                builder, ref seq,
                value, member.Member,
                "select", null,
                "value", selectedIndex,
                required, disabled,
                args => OnChange(value, args)
            );

            _keyMap = new Dictionary <int, TID>();

            //

            builder.OpenRegion(++seq);
            int iSeq = -1;
            for (var i = 0; i < options.Count; i++)
            {
                IOption <TID> option = options[i];
                _keyMap[i] = option.Value;

                builder.OpenElement(++iSeq, "option");
                builder.AddAttribute(++iSeq, "value", i);

                ++iSeq;
                if (option.Disabled)
                {
                    builder.AddAttribute(iSeq, "disabled", "disabled");
                }

                ++iSeq;
                if (option.Value.Equals(v))
                {
                    builder.AddAttribute(iSeq, "selected", "selected");
                }

                builder.AddContent(++iSeq, option.OptionText);
                builder.CloseElement();
            }

            builder.CloseRegion();

            //

            if (selectedIndex == null)
            {
                builder.OpenElement(++seq, "option");
                builder.AddAttribute(++seq, "disabled", "disabled");
                builder.AddAttribute(++seq, "hidden", "hidden");
                builder.AddAttribute(++seq, "selected", "selected");
                builder.CloseElement();
            }

            InputBuilder.CloseInnerInput(builder);

            builder.CloseElement();
        };
Example #17
0
            protected override void BuildRenderTree(RenderTreeBuilder b)
            {
                int seq = -1;

                b.OpenElement(++seq, "div");
                b.AddAttribute(++seq, "class", "Integrant.Element.Component Integrant.Element.Component.Combobox");
                b.AddElementReferenceCapture(++seq, elemRef => Combobox._elementRef = elemRef);

                // Input

                b.OpenElement(++seq, "div");

                var classes = new ClassSet(
                    "Integrant.Element.Component.Combobox.Input",
                    "Integrant.Element.Override.Input"
                    );

                if (Combobox._isDisabled?.Invoke() == true)
                {
                    classes.Add("Integrant.Element.Override.Input:Disabled");
                }

                if (Combobox._isRequired?.Invoke() == true && Combobox._selected == null)
                {
                    classes.Add("Integrant.Element.Override.Input:FailsRequirement");
                }

                b.AddAttribute(++seq, "class", classes.ToString());

                b.OpenElement(++seq, "input");
                b.AddAttribute(++seq, "type", "text");
                b.AddAttribute(++seq, "value", Combobox.InputValue());
                b.AddAttribute(++seq, "data-has-selection", Combobox._selected != null);
                b.AddAttribute(++seq, "disabled", Combobox._isDisabled?.Invoke() == true);
                b.AddAttribute(++seq, "required", Combobox._isRequired?.Invoke() == true);

                ++seq;
                if (Combobox._placeholder != null)
                {
                    b.AddAttribute(seq, "placeholder", Combobox._placeholder.Invoke());
                }

                b.AddAttribute(++seq, "onclick",
                               EventCallback.Factory.Create <MouseEventArgs>(this, Combobox.OnInputClick));
                b.AddAttribute(++seq, "onfocus",
                               EventCallback.Factory.Create <FocusEventArgs>(this, Combobox.OnInputFocus));
                b.AddAttribute(++seq, "onblur",
                               EventCallback.Factory.Create <FocusEventArgs>(this, Combobox.OnInputBlur));
                b.AddAttribute(++seq, "onkeydown",
                               EventCallback.Factory.Create <KeyboardEventArgs>(this, Combobox.OnInputKeyDown));
                b.AddAttribute(++seq, "oninput",
                               EventCallback.Factory.Create <ChangeEventArgs>(this, Combobox.OnInputInput));

                b.CloseElement();
                b.CloseElement();

                // Dropdown

                b.OpenElement(++seq, "div");
                b.AddAttribute(++seq, "class", "Integrant.Element.Component.Combobox.Dropdown");
                b.AddAttribute(++seq, "data-shown", Combobox._shown);

                b.OpenRegion(++seq);

                int seq2 = -1;

                for (var i = 0; i < Combobox.Options().Length; i++)
                {
                    IOption <T> o        = Combobox.Options()[i];
                    bool        selected = Combobox._selected?.Value.Equals(o.Value) == true;
                    bool        focused  = Combobox._focused?.Value.Equals(o.Value) == true;
                    bool        matches  = Combobox.Matches(o);

                    b.OpenElement(++seq2, "div");
                    b.AddAttribute(++seq, "class", "Integrant.Element.Component.Combobox.Option");
                    b.AddAttribute(++seq2, "hidden", !matches);
                    b.AddAttribute(++seq2, "data-i", i);
                    b.AddAttribute(++seq2, "data-focused", focused);
                    b.AddAttribute(++seq2, "data-selected", selected);
                    b.AddAttribute(++seq2, "data-disabled", o.Disabled);

                    b.AddAttribute(++seq2, "onmousedown",
                                   EventCallback.Factory.Create <MouseEventArgs>(this, Combobox.OnOptionMouseDown));
                    b.AddEventPreventDefaultAttribute(++seq2, "onmousedown", true);

                    b.AddAttribute(++seq2, "onclick",
                                   EventCallback.Factory.Create <MouseEventArgs>(this,
                                                                                 args => Combobox.OnOptionClick(args, o)));

                    b.AddContent(++seq2, o.OptionText);

                    b.CloseElement();
                }

                b.CloseRegion();

                b.CloseElement();

                //

                b.CloseElement();
            }